我之前没有任何问题,但我今天已经检查过,我收到以下错误:邮件程序错误:SMTP连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting。我在 Heroku app 上运行我的网站。我使用最新版本的 php Mailer 和 google smtp 服务器。我可以使用任何替代smtp服务器吗?这是我的剧本:
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
if(empty($_POST['Email'])){
$_POST['Email']= "";
}
if(empty($_POST['Name'])){
$_POST['Name']= "";
}
if(empty($_POST['Subject'])){
$_POST['Subject']= "";
}
if(empty($_POST['message'])){
$_POST['message']= "";
}
if (isset($_POST["message"]) && !empty($_POST["message"])) {
$mymail=smtpmailer("webdominar1@gmail.com",$_POST['Email'],
$_POST['Name'], $_POST['Subject'], $_POST['message']);
}else{
header('Location: http://webdominar.xyz'); exit();
}
function smtpmailer($to, $from, $from_name, $subject, $body) {
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'test@gmail.com';
$mail->Password = '1234';
$mail->SetFrom($from, $from_name);
$mail->Subject = "Webdominar Contact form ~Name: $from_name ~ subject: $subject
on http://webdominar.xyz ";
$mail->CharSet = 'UTF-8';
$mail->isHTML(true); // Set email format to HTML
$mail->Body = "blabla" ; //end body
$mail->AddAddress($to);
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Well done $from_name, your message has been sent!\nWe will reply to the following email: $from"
. "<br>Your Message: $body";
}
} //end function smtpmailer
?>