[英]SMTP ERROR: Failed to connect to server: Permission denied (13)
再會!
我試圖讓我的 phpmailer 在我的共享主機(freehostia.com)
,但我總是收到此錯誤。 我的gmail的用戶名和密碼是正確的,其余的設置是這樣的:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'tls://smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail@gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mymail@gmail.com', 'ASAPHOT Administrator'); // Add a recipient
$mail->addAddress('sorianorobertc@gmail.com'); // Name is optional
$mail->addReplyTo('mymail@gmail.com', 'ASAPHOT Administrator');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'it works';
$mail->Body = 'it works';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
openssl 在php.ini
也沒有注釋。 我在這里錯過了什么嗎? 謝謝你。
完整的錯誤信息:
Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: Permission denied (13)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我們先來揭曉答案! 嘗試使用以下命令:
$ getsebool httpd_can_sendmail
如果顯示: httpd_can_sendmail --> off
用這個打開它:
$ sudo setsebool -P httpd_can_sendmail 1
然后嘗試再次發送電子郵件。
這個解決方案來自這個很棒的頁面。
正如本文所指出的,您可能還需要嘗試sudo setsebool -P httpd_can_network_connect 1
。 而對於我由 DigitalOcean 托管的 CentOS 7 虛擬機,則沒有必要。
我遇到的問題是無法使用 SMTP 身份驗證支持模塊從 Drupal 網站發送電子郵件,該模塊依賴於底層的 PHPMailer。 使用的 SMTP 服務器是 Google。
順便說一句,我懷疑這是 OpenSSL 證書問題並做了一些測試但沒有運氣。 因此,通過將 PHPMailer 源代碼中的$SMTPDebug
級別設置為 2,我能夠捕獲“權限被拒絕 (13)”錯誤消息。
這表明在您的 PHP 安裝中禁用了 fopen 包裝器或套接字函數。 在共享主機中並不罕見。 運行phpinfo()
應該會告訴你。
您可能可以使用$mail->isMail();
並跳過通過 ISP 的郵件服務器而不是 SMTP 發送的身份驗證,但要注意 SPF 問題。
感謝您的解決方案,它對我有幫助。 我只是將項目移到新服務器上,一邊測試一邊發現郵件功能
問題是 freehostia 的免費托管會阻止發出的郵件。
Freehostia 在免費計划中阻止了以下列表。 (巧克力)
-郵遞員
-卷曲
-肥皂得到
-xml 獲取
這對 http 很重要
use this
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "ssl://smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
如果這不起作用,請嘗試下面的 php 代碼。
郵件($to,$subject,$message);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.