2017-04-11 192 views
-1

我已被搜查了很多小時來解決我的問題,我失敗了。錯誤與郵件錯誤:SMTP連接()失敗

這是我簡單的代碼使用PHPMailer的Gmail在XAMPP發送電子郵件,每次得到這個錯誤

Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

,這是我PHP代碼

<?php 
require_once('PHPMailer/PHPMailerAutoload.php'); 

$mail = new PHPMailer(); 
$mail->isSMTP(); 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->HOST = 'smtp.gmail.com'; 
$mail->PORT = '465'; 
$mail->isHTML(); 
$mail->Username = '##myemail##@gmail.com'; 
$mail->Password = '##mypass##'; 
$mail->SetFrom('[email protected]'); 
$mail->Subject = 'Hello World'; 
$mail->Body = 'A test email!'; 
$mail->AddAddress('[email protected]'); 


if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 

?> 

請幫幫我。

+1

你檢查了維基? https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#smtp-error-could-not-connect-to-smtp-host – modsfabio

+0

你很可能有認證錯誤,但你應該設置'$ mail-> SMTPDebug = 2 '讓我們知道錯誤是什麼。 – Linek

+1

[PHPMailer,SMTP connect()失敗,可能出現與Gmail錯誤](http://stackoverflow.com/questions/25924651/phpmailer-smtp-connect-failed-error-with-gmail) – Synchro

回答

相關問題