donglian4879
2017-01-05 07:47
浏览 121
已采纳

通过本地smtp服务器发送电子邮件

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

图片转代码服务由CSDN问答提供 功能建议

代码:

 &lt;?php 
require'PHPMailer  /PHPMailerAutoload.php'; 
nnnnmail = new PHPMailer; 
 
 $ mail-&gt; CharSet =“utf-8”; 
 $ mail-&gt; isSMTP();  //设置邮件程序使用SMTP 
 $ mail-&gt; Host ='172.17.224.12';  //指定主SMTP服务器和备用SMTP服务器
 $ mail-&gt; SMTPAuth = false;  //启用SMTP身份验证
 // $ mail-&gt; Username ='***';  // SMTP用户名
 // $ mail-&gt;密码='***';  // SMTP密码
 $ mail-&gt; SMTPSecure ='TLS';  //启用TLS加密,`ssl`也接受
 $ mail-&gt; Port = 25;  // TCP端口连接到
 
 $ mail-&gt; setFrom('theitslt @ example.com','Company.com'); 
 $ mail-&gt; addReplyTo('theitslt@example.com')  ; 
 $的MAIL-&GT; addAddress('dichitslt@example.com');  //添加收件人
 
 $ mail-&gt; isHTML(true);  //将电子邮件格式设置为HTML 
 
 $ bodyContent ='&lt; h1&gt;如何使用PHP在Localhost中通过CodexWorld发送电子邮件&lt; / h1&gt;'; 
 $ bodyContent。='&lt; p&gt;这是HTML 使用PHP脚本从localhost发送的电子邮件&lt; b&gt; CodexWorld&lt; / b&gt;&lt; / p&gt;'; 
 
 $ mail-&gt; SMTPDebug = 2; 
 $ mail-&gt; Subject ='来自Localhost的电子邮件 by CodexWorld'; 
 $ mail-&gt; Body = $ bodyContent; 
 
if(!$ mail-&gt; send()){
 echo'无法发送消息。&lt; br&gt;'; 
  echo'Mailer Error:'。  $ mail-&gt; ErrorInfo; 
 
}其他{
 echo'Fessage已发送'; 
} 
?&gt; 
   
 
 

我运行此代码,它说消息已发送。 但是,当我查看我的电子邮件时,会有一条通知说通过我的代码发送的电子邮件被退回。

可能出现什么问题? 是我的代码中的配置还是服务器?

退回电子邮件的屏幕截图 < / p>

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douchuanchai2793 2017-01-11 07:39
    已采纳

    For those who encounter the same problem, what resolved to this problem is smozgur's answer.

    I think the server you are trying to send email through php - your local server - is not authorized to send email and considered as SPAM (like someone else is trying to send email by using your credentials). When I need to make my scripts sends email from the server, then I add my server IP as the SPF record in the DNS records. That way, my email server knows that IP is sending email in my knowledge and allows. In your case, I think you can likely add your IP to temporarily solve the problem. But you need to do that for the production server IP later as well. If this is the case of course..

    I contacted supervisor and told him the status of the email function, which is emails are being sent, but the mail server returns the emails to the sender. Also, the possible cause of the problem, which is the local server is not authorized to send email and considered as SPAM. Lastly, the possible solution, which is add the server IP as the SPF record in DNS record.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题