【问题标题】:phpmailer does not workphpmailer 不工作
【发布时间】:2014-03-14 09:48:46
【问题描述】:

我必须通过 Gmail 发送邮件,但我不知道如何配置 phpmailer。 当我使用phpmailer 时,它给了我一个尚未经过身份验证但电子邮件和密码正确的错误。

代码如下:

require '../class.phpmailer.php';

try {
    $mail = new PHPMailer(true);                 //New instance, with exceptions enabled

    $body             = file_get_contents('contents.html');
    $body             = preg_replace('/\\\\/','', $body); //Strip backslashes

    $mail->IsSMTP();                             // tell the class to use SMTP
    $mail->SMTPAuth   = true;                    // enable SMTP authentication
    $mail->Port       = 25;                      // set the SMTP server port
    $mail->Host       = "smtp.gmail.com";        // SMTP server
    $mail->Username   = "yuliy.x.95@gmail.com";  // SMTP server username
    $mail->Password   = "mypassword";            // SMTP server password

    $mail->IsSendmail();                         // tell the class to use Sendmail

    $mail->AddReplyTo("k.yuliy@yahoo.it","First Last");

    $mail->From       = "name@domain.com";
    $mail->FromName   = "First Last";

    $to = "k.yuliy@yahoo.it";

    $mail->AddAddress($to);

    $mail->Subject  = "First PHPMailer Message";

    $mail->AltBody  = "To view the message, please use an HTML compatible email viewer!";                                            // optional, comment out and test
    $mail->WordWrap = 80;                      // set word wrap

    $mail->MsgHTML($body);

    $mail->IsHTML(true);                         // send as HTML 

    $mail->Send();
    echo 'Message has been sent.';
} catch (phpmailerException $e) {
    echo $e->errorMessage();
}
?>

我收到此错误:

无法执行:/var/qmail/bin/sendmail

【问题讨论】:

  • 你看过any of these吗?
  • 服务器的操作系统是什么?

标签: php email phpmailer


【解决方案1】:

您需要为 Gmail 使用端口 465

$mail->Port       = 465;    

【讨论】:

    【解决方案2】:

    使用命令 $mail->isSMTP() 您选择 SMTP 作为传输。

    但在发送邮件之前,您将切换回使用带有$mail->isSendmail() 的本地安装的 sendmail。

    不要这样做,您当前的错误将会消失。可能会出现一个新的。

    【讨论】:

      【解决方案3】:

      除了 sendmail 可能没有被正确调用之外,您还试图连接到端口 25。您不能这样做。 smtp.gmail.com 需要 SSL -- 这不是可选的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-21
        • 2014-08-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多