我尝试使用phpmailer从我的localhost发送邮件,但它无法正常工作。我真的复制并粘贴了一个工作版本的代码(可以在我的网站上运行),但是当我尝试发送邮件时,它给了我以下错误:
SMTP ERROR: Failed to connect to server: Operation timed out (60)
SMTP connect() failed.
Mailer Error: SMTP connect() failed.
我尝试过的事情:
上以当前形式运行一切
require_once("vendor/phpmailer/phpmailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->SMTPDebug = 2;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "example.com";
$mail->Port = 587;
$mail->Username = "username@example.com";
$mail->Password = "password";
$mail->From = "username@example.com";
$mail->FromName = "name";
$mail->addAddress("user@gmail.com");
$mail->Subject = "Subject";
$mail->Body = "Body";
if(!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
echo "Message has been sent successfully";
}
提前致谢