我剛剛開始使用PHP進行編碼。我試圖發送郵件,但它會引發錯誤郵件錯誤:SMTP連接()失敗。本地主機上的SMTP連接()失敗錯誤
下面是我使用的代碼:
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = gethostbyname('ssl://smtp.gmail.com');
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
$mail->Username = '[email protected]';
$mail->Password = '********';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('[email protected]','Abc') ;
$mail->addReplyTo('[email protected]');
$mail->addAddress("[email protected]",'No REPLY');
$mail->isHTML(true);
$mail->Body = "12345";
$mail->Subject = "<b>OTP for password reset<b>";
$mail->Body = "Hi! Your OTP is : ";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
echo 'Message has been sent.';
}
任何幫助,將不勝感激。
這是哪個版本的php? – abeyaz
檢查此:[與PHPMailer處理錯誤](https://stackoverflow.com/questions/2386544/error-handling-with-phpmailer) –
PHP版本是5.6.25 –