douyongwan5946 2014-09-29 06:36
浏览 112

使用phpmailer发送电子邮件时调用Mail()而不连接

I am trying to send mail using phpmailer but it is giving error

<?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";
    }

?>
it is showing error like Error sending:

"Error sending: The following From address failed: mg@gmail.com : Called Mail() without being connected"


i try with adding code $mail->SMTPDebug = 1; then it is showing error like below

SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) The following From address failed: mg@gmail.com : Called Mail() without being connected

  • 写回答

1条回答 默认 最新

  • duanguan3863 2014-09-29 06:47
    关注

    Change this,

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

    You are mixing single quotes and double quotes

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料