1

Code:

<?php
require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->CharSet="utf-8";
$mail->isSMTP();                                   // Set mailer to use SMTP
$mail->Host = '172.17.224.12';                    // Specify main and backup SMTP servers
$mail->SMTPAuth = false;                            // Enable SMTP authentication
//$mail->Username = '***';          // SMTP username
//$mail->Password = '***'; // SMTP password
$mail->SMTPSecure = 'TLS';                         // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;                                 // TCP port to connect to

$mail->setFrom('itslt@example.com', 'Company.com');
$mail->addReplyTo('itslt@example.com');
$mail->addAddress('dichitslt@example.com');   // Add a recipient

$mail->isHTML(true);  // Set email format to HTML

$bodyContent = '<h1>How to Send Email using PHP in Localhost by CodexWorld</h1>';
$bodyContent .= '<p>This is the HTML email sent from localhost using PHP script by <b>CodexWorld</b></p>';

$mail->SMTPDebug = 2;
$mail->Subject = 'Email from Localhost by CodexWorld';
$mail->Body    = $bodyContent;

if(!$mail->send()) {
    echo 'Message could not be sent.<br>';
    echo 'Mailer Error: ' . $mail->ErrorInfo;

} else {
    echo 'Message has been sent';
}
?>

When I run this code, it says message has been sent. However, when I look at my email, there's a notification saying that the email sent through my code was bounced back.

What could be the possible problem? was it the configuration in my code or was it the server?

screencap of the bounce back email

4

1 回答 1

0

对于遇到同样问题的人来说,解决这个问题的是smozgur的回答。

我认为您尝试通过 php 发送电子邮件的服务器 - 您的本地服务器 - 无权发送电子邮件并被视为垃圾邮件(就像其他人试图使用您的凭据发送电子邮件一样)。当我需要让我的脚本从服务器发送电子邮件时,我将我的服务器 IP 添加为 DNS 记录中的 SPF 记录。这样,我的电子邮件服务器就知道 IP 正在我的知识范围内发送电子邮件并允许。在你的情况下,我认为你可以添加你的 IP 来暂时解决问题。但是您稍后也需要为生产服务器 IP 执行此操作。如果是这样的话当然..

我联系了主管并告诉他电子邮件功能的状态,即正在发送电子邮件,但邮件服务器将电子邮件返回给发件人。此外,问题的可能原因是本地服务器无权发送电子邮件并被视为垃圾邮件。最后,可能的解决方案是将服务器 IP 添加为 DNS 记录中的 SPF 记录。

于 2017-01-11T07:39:11.703 回答