【问题标题】:Sending email from website using Gmail SMTP server through PHP Mailer通过 PHP Mailer 使用 Gmail SMTP 服务器从网站发送电子邮件
【发布时间】:2014-10-28 23:22:07
【问题描述】:

我正在尝试通过 PHP Mailer 使用 Gmail SMTP 服务器从我的网站发送一封电子邮件,不幸的是它没有发送它没有显示任何类似 processForm.php 错误信息或消息已发送,下面是我的代码任何人都可以告诉我为什么它不起作用

processForm.php

<?php

print "hi";



include "class.phpmailer.php"; // include the class file name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxxxxxxx6@gmail.com";
$mail->Password = "xxxxxx";
$mail->SetFrom("arokxavi16@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("arokiaxavierraja16@gmail.com");
 if(!$mail->Send())
    {
    echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    echo "Message has been sent";
    }

    ?>

【问题讨论】:

    标签: php email ssl


    【解决方案1】:
    $mail->SMTPSecure = 'tls'; 
    

    使用它代替 ssl 可能会起作用。

    【讨论】:

      【解决方案2】:

      试试这个

      $mail->Host = "smtp.googlemail.com";
      

      而不是

      $mail->Host = "smtp.gmail.com";
      

      另一种解决方案也在这里。不使用 class.phpmailer.php

          $to = 'arokiaxavierraja16@gmail.com';
      
          $from =  'xxxxxx@gmail.com';
          $subject = 'Test';      
          $msg = 'hello';
          $headers = "From:". $from;
          $message = "Hello";
      
          if(!mail($to,$subject,$message,$headers)) { 
             echo 'Error'; 
          } 
          else {
            echo "Success";
          }
      

      【讨论】:

      • OP 已经在使用 phpmailer - 所以你的“答案”不会在此处添加任何新内容,或者与实际问题有关的任何内容。请仅在您对手头的问题有实际答案时才回答问题,而不仅仅是为了回答问题。
      • 在我的情况下,仅包括/使用没有整个 PHPMailer 的 class.phpmailer.php 它不起作用。所以我使用这种方式并且工作正常。所以你不能投票给我。 @Xavi 请尝试这种方式,让我知道它是否有效。
      • @herr mail() 没有身份验证。因此,收件人将收到带有不同标头的电子邮件,并且可能会在垃圾文件夹中获得它。
      猜你喜欢
      • 1970-01-01
      • 2022-01-09
      • 2014-10-15
      • 2011-08-11
      • 2010-10-17
      相关资源
      最近更新 更多