【问题标题】:Can't send Email with Outlook SMTP using PhpMailer and Codeigniter无法使用 PhpMailer 和 Codeigniter 通过 Outlook SMTP 发送电子邮件
【发布时间】:2020-06-06 18:03:48
【问题描述】:

每当我尝试使用:Phpmailer 发送电子邮件(outlook SMTP)时,我都会收到此错误:

2020-06-05 18:45:05 Connection: opening to smtp.office365.com:587, timeout=300, options=array()
2020-06-05 18:45:05 Connection: opened
2020-06-05 18:45:05 SERVER -> CLIENT: 220 AM0PR10CA0059.outlook.office365.com Microsoft ESMTP MAIL Service ready at Fri, 5 Jun 2020 18:45:05 +0000
2020-06-05 18:45:05 SERVER -> CLIENT: 250-AM0PR10CA0059.outlook.office365.com Hello [82.165.86.40]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2020-06-05 18:45:05 CLIENT -> SERVER: STARTTLS
2020-06-05 18:45:05 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2020-06-05 18:45:05 SERVER -> CLIENT: 250-AM0PR10CA0059.outlook.office365.com Hello [82.165.86.40]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN XOAUTH2250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2020-06-05 18:45:05 CLIENT -> SERVER: AUTH LOGIN
2020-06-05 18:45:05 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2020-06-05 18:45:05 CLIENT -> SERVER: [credentials hidden]
2020-06-05 18:45:05 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2020-06-05 18:45:05 CLIENT -> SERVER: [credentials hidden]
2020-06-05 18:45:10 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [AM0PR10CA0059.EURPRD10.PROD.OUTLOOK.COM]
2020-06-05 18:45:10 SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful [AM0PR10CA0059.EURPRD10.PROD.OUTLOOK.COM]
SMTP Error: Could not authenticate.
2020-06-05 18:45:10 CLIENT -> SERVER: QUIT
2020-06-05 18:45:10 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2020-06-05 18:45:10 Connection: closed
SMTP Error: Could not authenticate.

我也尝试过使用 Codeigniter

Failed to authenticate password. Error:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

我尝试了两种方式,但都没有工作......

我正在使用 codeigniter 默认邮件类

这里是配置:

        $config = array(

            'smtp_crypto'  => 'tls', or 'startTls'
            'smtp_auth'  => true,
            'protocol'  => 'smtp',
            'smtp_host' => 'smtp.office365.com',
            'smtp_port' => 587,
            'smtp_timeout' => '7',
            'smtp_user' => 'email@account.com',
            'smtp_pass' => 'emailPassword', or 'APPPASSWORD'
            'mailtype'  => 'html',
            'charset'   => 'iso-8859-1',
            'wordwrap'  => TRUE,
            'validation'   => TRUE
        );

这是 Phpmailer 配置:

$mail->isSMTP();
$mail->Host     = 'smtp.office365.com';
$mail->SMTPAuth = false;
$mail->Username = 'email@account.com';
$mail->Password = 'emailPassword'; or 'APPPASSWORD'
$mail->SMTPSecure = 'tls', or 'startTls',
$mail->Port     =  587

有人遇到过这类问题吗? 寻求帮助!!!

【问题讨论】:

  • 您的凭据似乎有误。如果您完全确定它们是正确的,请联系 Outlook 支持,因为您的代码没有任何问题。
  • SMTP ERROR: Password command failed: 535 5.7.3 Authentication unsuccessful
  • 这条线看起来有点奇怪$mail->SMTPSecure = 'tls', or 'startTls',
  • 还有这行'smtp_crypto' => 'tls', or 'startTls'
  • 还有这行'smtp_pass' => 'emailPassword', or 'APPPASSWORD'

标签: php codeigniter email outlook phpmailer


【解决方案1】:

我遇到了一些证书问题,这就是我最终使用它的方式:

<?php
$mailusername= "******";
$mailpassword= "******";
$mailhost= "smtp.office365.com";
$to="*******";
$subject="test";
$body="abcdef";


require_once('PHPMailer-master/class.phpmailer.php');
require_once('PHPMailer-master/class.smtp.php');


$mail = new PHPMailer();


$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Host       = $mailhost;
$mail->SMTPDebug  = 1;
$mail->SMTPAuth   = true;
$mail->Port       = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
$mail->Username   = $mailusername;
$mail->Password   = $mailpassword;

$frommail = $mailusername;//$this->from;
$fromname = "Mailbot";
$mail->SetFrom($frommail, $fromname);


$address = $to;
$adrname = "";
$mail->AddAddress($address, $adrname);

$mail->Subject = $subject;
$mail->Body = $body;

if(!$mail->Send()) {
    //echo "Mailer Error: " . $mail->ErrorInfo;
    print( "sendViaSMTP() - failed to send email");
} else {
    print( "sendViaSMTP() - success sending email");
    // all good
}


?>

(1) 对我来说,棘手的部分是SMTPOptions()

(2) 另一个棘手的部分是使用 latest PHPMailer() lib。因为SMTPOptions() 只支持较新的PHPMailer()

(3) 使用“no-verify”选项是不安全的。但是由于设置/配置问题需要在某些服务器上。

更新了我的代码

我正在使用 PHPMailer

   public $Version = '5.2.8';

【讨论】:

  • 没有运气...同样的错误....2020-06-06 19:48:36 SERVER -&gt; CLIENT: 535 5.7.3 Authentication unsuccessful [AM0PR04CA0034.eurprd04.prod.outlook.com]
  • 你可以尝试设置 $mail->SMTPSecure = "ssl";
  • 更新后的示例代码应该可以工作。如果不是,我建议使用 SMTP 测试从任何其他电子邮件程序发送。因为我猜您的登录数据不正确或您的帐户未启用允许通过外部程序发送。
  • 我已经解决了问题....我在 Office 365 管理控制台中更改了几件事...但感谢您的帮助:)
  • @fahimarifen 我在尝试将 Office 365 用作 CI 中的 smtp 服务器时遇到了同样的问题,您能否分享您在 Office 365 管理控制台中所做的更改?谢谢
猜你喜欢
  • 2011-04-06
  • 1970-01-01
  • 1970-01-01
  • 2017-10-05
  • 2022-07-20
  • 2016-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多