2016-06-27 10 views
2

私はPHPMailerを使用してSMTPメールを送信しています。 WordPressサイトで同じ設定を使用してもうまく動作します。しかし、私の優先事項は、カスタムPHPページで使用することです。また、次のエラーが発生しています。サーバへの接続に失敗しました:Connection refused(111)

SMTPエラー:サーバーへの接続に失敗しました:接続が拒否されました(111) SMTP connect()が失敗しました。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting メーラーエラー:SMTP connect()に失敗しました。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

マイコードは、私はあなたがエラーメッセージまたはそれが指すドキュメントを読んでいない収集

<?php 
ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL); 

require 'emails/PHPMailer/PHPMailerAutoload.php'; 

//Create a new PHPMailer instance 
$mail = new PHPMailer; 
//Tell PHPMailer to use SMTP 
$mail->isSMTP(); 
//Enable SMTP debugging 
// 0 = off (for production use) 
// 1 = client messages 
// 2 = client and server messages 
$mail->SMTPDebug = 2; 
//Ask for HTML-friendly debug output 
$mail->Debugoutput = 'html'; 
//Set the hostname of the mail server 
$mail->Host = "smtp.gmail.com"; 
//Set the SMTP port number - likely to be 25, 465 or 587 
$mail->Port = 587; 
//Whether to use SMTP authentication 
$mail->SMTPAuth = true; 
//Username to use for SMTP authentication 
$mail->Username = "[email protected]"; 
$mail->Password = "password"; 
//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'Zubair Mushtaq'); 
//Set an alternative reply-to address 
$mail->addReplyTo('[email protected]', 'Secure Developer'); 
//Set who the message is to be sent to 
$mail->addAddress('[email protected]', 'Abulogicss'); 
//Set the subject line 
$mail->Subject = 'PHPMailer SMTP test'; 
//Read an HTML message body from an external file, convert referenced images to embedded, 
//convert HTML into a basic plain-text alternative body 
$mail->msgHTML("convert HTML into a basic plain-text alternative body"); 
//Replace the plain text body with one created manually 
$mail->AltBody = 'This is a plain-text message body'; 

//send the message, check for errors 
if (!$mail->send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
+0

このその作業罰金を試すの下にここにあります。 – Synchro

答えて

1

<?php 
    include "emails/PHPMailer/PHPMailerAutoload.php"; 

    //Create a new PHPMailer instance 
    $mail = new PHPMailer(); 

    $mail->IsSMTP(); 
    $mail->SMTPDebug = 1; 
    $mail->SMTPAuth = true; 
    $mail->SMTPSecure = 'ssl'; 
    $mail->Host = "smtp.gmail.com"; 

    $mail->Port = 465; 
    $mail->IsHTML(true); 
    //Username to use for SMTP authentication 
    $mail->Username = "@gmail.com"; 
    $mail->Password = ""; 
    //Set who the message is to be sent from 
    $mail->setFrom('[email protected]', 'Zubair Mushtaq'); 
    //Set an alternative reply-to address 
    $mail->addReplyTo('[email protected]', 'Secure Developer'); 
    //Set who the message is to be sent to 
    $mail->addAddress('[email protected]', 'Abulogicss'); 
    //Set the subject line 
    $mail->Subject = 'PHPMailer SMTP test'; 
    //Read an HTML message body from an external file, convert referenced images to embedded, 
    //convert HTML into a basic plain-text alternative body 
    $mail->msgHTML("convert HTML into a basic plain-text alternative body"); 
    //Replace the plain text body with one created manually 
    $mail->AltBody = 'This is a plain-text message body'; 

    //send the message, check for errors 
    if (!$mail->send()) { 
     echo "Mailer Error: " . $mail->ErrorInfo; 
    } else { 
     echo "Message sent!"; 
    } 

enter image description here

+0

Thakns Ashu。それは私の問題を解決します。しかし、あなたの電子メールとパスワードを使用して私の問題の解決ではありません。私はちょうど私のGmailのアカウントがsmtpで動作するようにしたいです。再度、感謝します。 –

+0

これをオンにするhttps://www.google.com/settings/security/lesssecureapps –

+0

こちらもやりました。そのprobleはgoDaddyがホスティングしていた。彼らはこれをデバッグするために私の2日間を無駄にした。とにかくあなたの大きな助けに感謝します。 –

関連する問題