我想下面的代碼來發送郵件 卻是露出無法發送電子郵件在PHP
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
和Gmail是通知我登入嘗試遭拒
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = '*******';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->From = '[email protected]';
$mail->FromName = 'asdf ';
$mail->addAddress('[email protected]', 'sadf ');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = "Using PHPMailer";
$mail->Body = "Hi Iam using PHPMailer library to sent SMTP mail from localhost";
if(!$mail->send()) {
echo "Message could not be sent.";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
如何解決上面的問題?
請問您的主機的防火牆具有端口587傳出打開? – Blaatpraat
出於好奇,你有沒有嘗試使用** ssl的端口465和25 **? – Torxed
是兩個端口都顯示相同的問題 – xrcwrn