【问题标题】:Called Mail() without being connected while sending email using phpmailer使用phpmailer发送电子邮件时调用Mail()而不连接
【发布时间】:2014-09-29 06:36:24
【问题描述】:

我正在尝试使用 phpmailer 发送邮件,但它给出了错误

<?php
   include("/mail/class.phpmailer.php");

    // Basic Header Input
    $mail = new PHPMailer();

    $mail->IsSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;
    $mail->Username = 'username'; // your GMail user name
    $mail->Password = 'password';           //"Password";
    // ---------- adjust these lines ---------------------------------------

    $mail->From= 'mg@gmail.com';
    $mail->FromName="My site's mailer";
    $mail->AddAddress("mg123@gmail.com");
    $mail->Subject = "Your invoice";

    $mail->IsHTML(false);
    $mail->AddAttachment('test1.pdf', 'invoice.pdf'); // attach files/invoice-user-1234.pdf, and rename it to invoice.pdf
    $mail->Body = "Please find your invoice attached.";
    if(!$mail->Send())
    {
       echo "Error sending: " . $mail->ErrorInfo;;
    }
    else
    {
       echo "Letter is sent";
    }

?>
它显示错误,例如错误发送:

"发送错误:以下发件人地址失败: mg@gmail.com : 在没有连接的情况下调用 Mail()"


我尝试添加代码 $mail->SMTPDebug = 1;然后它显示如下错误

SMTP -> 错误:无法连接到服务器: php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。 (0) 以下发件人地址失败:mg@gmail.com : 在没有连接的情况下调用 Mail()

【问题讨论】:

  • 使用这个 $mail->From="mg@gmail.com";
  • 单引号未完成
  • 现在告诉我这行得通吗?
  • 还有 $mail->FromName="My site\'s mailer";
  • 感谢您的回复,但它不起作用。

标签: php phpmailer


【解决方案1】:

改变这个,

$mail->From= 'mg@gmail.com';

你在混合单引号和双引号

【讨论】:

  • 感谢您的回复,我也尝试过,但同样的错误存在
  • @MGaidhane heck class.phpmailer.php 连接正确吗?
  • 我检查了它,它工作正常。我收到类似.....“SMTP -> 错误:无法连接到服务器:php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。(0)”
猜你喜欢
  • 2017-06-05
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多