2017-02-15 76 views
2

我使用phpmailer(smtp)發送電子郵件。我的網站託管在Godaddy上。 我讀過,phpmailer不與Godaddy合作。所以嘗試了多種解決方案發送電子郵但沒有任何工作。 錯誤消息顯示 SMTP - >錯誤:無法連接到服務器:連接被拒絕(111)SMTP連接()失敗。PHP郵件程序拒絕GoDaddy服務器的SMTP連接

在這裏添加代碼,有助於解決問題。

<?php 
require 'vendor/autoload.php';; 
$body = 'Hi this is test message'; 
$mail    = new PHPMailer(); 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "relay-hosting.secureserver.net"; // SMTP server    
$mail->SMTPDebug = 2; 
$mail->Debugoutput = 'html'; 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Port  = 25;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // SMTP account username 
$mail->Password = "*****"; 

$mail->SetFrom('[email protected]', 'Web developer'); 

$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; 
$mail->MsgHTML($body); 
$address = "[email protected]"; 
$mail->AddAddress($address, "John Doe"); 
    if(!$mail->Send()) { 
echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
echo "Message sent!"; 
} 

?>

+0

是否返回任何錯誤? – Mohammad

+0

檢查PEAR Mail是否安裝在服務器上,如果是可以用它作爲PHPMailer的替代品。 https://pear.php.net/manual/en/package.mail.mail.php – Auris

+0

嘗試發送它像這樣的郵件標識,並檢查它是否正在發送。如果它是鼻涕的工作,那麼讓我們試試其他的$ toMail =「[email protected]」; –

回答

0

更改MX記錄設置,並檢查一次。 在cPanel Mail部分搜索MX條目維護。 然後選擇相關的域並將電子郵件路由更改爲遠程郵件交換器。 添加所有的谷歌MX記錄,因爲它們在你的域配置。 有關如何配置域Click here

並設置SMTP_SERVER像這樣SMTP_SERVER本地主機的詳細信息:本地主機

2

設置SMTPOptions解決我的問題。

<?php 
require 'vendor/autoload.php';; 
$body = 'Hi this is test message'; 
$mail    = new PHPMailer(); 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->SMTPOptions = [ 
     'ssl' => [ 
      'verify_peer' => false, 
      'verify_peer_name' => false, 
      'allow_self_signed' => true, 
     ], 
    ]; 
    $mail->Host  = "mail.domain.com"; // SMTP server    
    $mail->SMTPDebug = 2; 
    $mail->Debugoutput = 'html'; 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->SMTPSecure = ''; // Enable TLS encryption, `ssl` also accepted 
    $mail->Port = 587; 

    $mail->Username = "[email protected]"; // SMTP account username 
    $mail->Password = "*****"; 

    $mail->SetFrom('[email protected]', 'Web developer'); 

    $mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; 
    $mail->MsgHTML($body); 
    $address = "[email protected]"; 
    $mail->AddAddress($address, "John Doe"); 
    if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    } else { 
    echo "Message sent!"; 
    } 
?>