首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Phpmailer无法发送邮件

Phpmailer无法发送邮件
EN

Stack Overflow用户
提问于 2015-09-07 17:22:40
回答 1查看 858关注 0票数 0

我正在尝试使用phpmailer发送邮件。mail->Send返回true,但邮件未送达

代码语言:javascript
复制
<?php
try {
    require_once('include/class.phpmailer.php');
    $mail = new PHPMailer(true);
    $mail->MailerDebug = true;
    $mail->IsSendmail();
    $mail->From = "library@capitalvia.com";
    $mail->FromName = "Library | CapitalVia";
    $mail->AddAddress("kanhaiya.lal@capitalvia.com", "Kanhaiyalal");
    $mail->AddReplyTo("library@capitalvia.com", "Library | CapitalVia");
    $mail->IsHTML(true);
    $mail->Subject = "Here is the subject";
    $mail->Body = "This is the HTML message body <b>in bold!</b>";
    $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
    if ($mail->Send())
        echo "Message has been sent";
} catch (phpmailerException $e) {
    echo $e->errorMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}
?>
EN

回答 1

Stack Overflow用户

发布于 2015-09-07 18:01:12

我的第一个猜测是您忘记了配置smtp服务器。如果没有提供smtp服务器,PHPMailer类将无法发送电子邮件。尝试添加如下所示的内容:

代码语言:javascript
复制
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
// OR this if authentication is needed
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "yourname@yourdomain"; // SMTP account username
$mail->Password   = "yourpassword";        // SMTP account password

此信息可在电子邮件应用程序(Outlook、Mail、Thunderbird等)中电子邮件帐户的配置/属性中找到。

This是Gmail的一个例子。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32435190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档