在邮件服务器PHPMailer中请求SMTP身份验证

我正在尝试使用PHPmailer发送邮件.我的webhost已经说过,如果邮件通过他们的数据中心进行中继,则不需要凭据.这是我的代码:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

$mail->SMTPSecure = 'ssl';
$mail->SMTPDebug    = 2;
$mail->isSMTP();

$mail->Host         = 'smtpgateway.webhost.com';
$mail->SMTPAuth     = false;
$mail->SMTPSecure   = false;
$mail->port         = 25;
$mail->setFrom('info@mydomain.com', 'Test');
$mail->Subject      = $email_subject;
$mail->Body         = $email_body;
$mail->addAddress($email, $name);
$mail->isHTML(true);
if($mail->send())
{
    echo "Success";
}

但是在尝试发送电子邮件时出现此错误:

2018-08-21 10:07:03 CLIENT -> SERVER: MAIL FROM: info@mydomain.com

2018-08-21 10:07:03 SERVER -> CLIENT: 250 OK

2018-08-21 10:07:03 CLIENT -> SERVER: RCPT TO:test@example.com

2018-08-21 10:07:03 SERVER -> CLIENT: 550-Please turn on SMTP Authentication in your mail client. (mydomain.com)550-[10.100.15.115]:41032 is not permitted to relay through this server without550 authentication.

2018-08-21 10:07:03 SMTP ERROR: RCPT TO command failed: 550-Please turn on SMTP Authentication in your mail client (mydomain.com)550-[10.100.15.115]:41032 is not permitted to relay through this server without550 authentication.

解决方法:

尝试没有任何SMTP详细信息,因为您可能不需要使用主机所说的SMTP.

$mail->setFrom('info@mydomain.com', 'Test');
$mail->Subject      = $email_subject;
$mail->Body         = $email_body;
$mail->addAddress($email, $name);
$mail->isHTML(true);
if($mail->send())
{
    echo "Success";
}

值得一试,让我知道它是否工作,但我猜你这里不需要SMTP.

检查一下,类似的问题:PHPmailer without using SMTP

上一篇:PHPMailer挂起发送邮件


下一篇:php – 带有str_replace的HTML电子邮件模板