dongmibeng5885 2016-01-12 23:15
浏览 87

PHPMailerAutoload成功消息,但不发送任何电子邮件

I am trying to send an email using the gmail smtp server as a relay in php. I am programming in webmatrix server and I use PHPMailerAutoload library to send the emails.My operating system is windows 7 64 bit.I already have configured php.ini to use gmail smtp server.When running the code i get the success message but no emails is sent.Could anyone please help me find the problem,thanks.Here is part of my code:

     $mail = new PHPMailer(true);

           //Send mail using gmail
           if($send_using_gmail){
           $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
    $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    $mail->Port = 465; // set the SMTP port for the GMAIL server
    $mail->Username = "example"; // GMAIL username
    $mail->Password = "password"; // GMAIL password
}

//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom("example@gmail.com", "name");
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
$mail->SMTPDebug = true;

try{
    $mail->Send();
    echo "Success!";

} catch(Exception $e){
    //Something went bad
    echo "Fail - " . $mail->ErrorInfo;
}
  • 写回答

1条回答 默认 最新

  • doucha7329 2016-02-02 12:49
    关注

    Download the wrapper file PHPMailer, import the file as shown below.

     require '../PHPMailer/PHPMailerAutoload.php';
    
        $mail = new PHPMailer;
    
           //Send mail using gmail
         if($send_using_gmail){
           $mail->IsSMTP(); // telling the class to use SMTP
           $mail->SMTPAuth = true; // enable SMTP authentication
           $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
           $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
           $mail->Port = 465; // set the SMTP port for the GMAIL server
           $mail->Username = "example"; // GMAIL username
          $mail->Password = "password"; // GMAIL password
        }
    
     //Typical mail data
        $mail->AddAddress($email, $name);
        $mail->SetFrom("example@gmail.com", "name");
        $mail->Subject = "My Subject";
        $mail->Body = "Mail contents";
        $mail->SMTPDebug = true;
    
        try{
           $mail->Send();
           echo "Success!";
    
         } catch(Exception $e){
        //Something went bad
            echo "Fail - " . $mail->ErrorInfo;
         }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算