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

使用phpmailer发送电子邮件时未连接调用Mail(),php,phpmailer,Php,Phpmailer,我正在尝试使用phpmailer发送邮件,但出现了错误 <?php include("/mail/class.phpmailer.php"); // Basic Header Input $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->SMTPSec

我正在尝试使用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";
    }
更改此选项

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

您正在混合使用单引号和双引号

使用此$mail->From=”mg@gmail.com";单报价未完成请立即告诉我这是否有效?以及$mail->FromName=“我的网站的邮件”;谢谢你的回复,但它不起作用。谢谢你的回复,我也尝试过这个,但同样的错误是there@MGaidhane检查class.phpmailer.php是否连接正确?我检查了它,它工作正常。我得到的错误就像。。。。。“SMTP->错误:无法连接到服务器:php\u网络\u getaddresses:getaddrinfo失败:未知此类主机。(0)”