我正在尝试使用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";
}
&GT?;
它显示错误发送错误:
&#34;发送错误:以下发件人地址失败: mg@gmail.com:在没有连接的情况下调用Mail()&#34;
我尝试添加代码$ mail-&gt; SMTPDebug = 1;然后它显示如下错误
SMTP - &gt;错误:无法连接到服务器: php_network_getaddresses:getaddrinfo失败:没有这样的主机。 (0)以下发件人地址失败:mg@gmail.com :调用Mail()而不连接
答案 0 :(得分:0)
改变这一点,
$mail->From= 'mg@gmail.com';
您正在混合使用单引号和双引号