2
我已經閱讀了網絡中的每個示例,但仍無法連接到GMAIL SMTP。下面是我運行的代碼:使用PHPMailer和GMAIL發送電子郵件SMTP
include("phpMailer/class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myUsername"; // SMTP username
$mail->Password = "myPassword"; // SMTP password
$mail->SMTPDebug = 1;
$webmaster_email = "[email protected]"; //Reply to this email ID
$email="[email protected]"; // Recipients email ID
$name="SomeonesName"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Me";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
我嘗試設置端口在這裏,我也有當前設置了在class.smtp.php文件中的以下內容:
$host = "ssl://smtp.gmail.com";
$port = 465;
我不斷收到相同的錯誤,我確定已啓用ssl。我得到的錯誤是:
SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.(10061)
我跟着http://deepakssn.blogspot.com/2006/06/gmail-php-send-email-using-php的例子-with.html – hera87
可能重複[使用GMail SMTP服務器從PHP頁面發送電子郵件](http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page) – Adi
我使用PHPMailer,而不是默認的Mail.php php.ini配置 – hera87