dongyan1899 2017-05-02 23:02 采纳率: 100%
浏览 502

PHP邮件错误:SMTP连接()失败

I had not any problems before, but i have checked today and i get the following error: Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting. I run my website on Heroku app. I use the latest version of php Mailer with google smtp servers. Are there any alternative smtp servers i can use? Here is my Script:

<?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!
We will reply to the following email: $from"
            . "<br>Your Message: $body";
}




} //end function smtpmailer



?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog