【发布时间】: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";
-
感谢您的回复,但它不起作用。