简体   繁体   中英

No email received when sending email from gmail using PHP Mailer

Below is the PHP Mailer code I use to send email from gmail to another mail server.

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->SMTPDebug = 1;
$mail->isSMTP();                                        
$mail->Host = 'smtp.gmail.com';                     
$mail->SMTPAuth = true;                                 
$mail->Username = 'distechktn@gmail.com';      
$mail->Password = 'mypassword';                        
$mail->SMTPSecure = 'tls';                              
$mail->Port = 587;                                      

$mail->From = 'distechktn@gmail.com';
$mail->FromName = 'Server';
$mail->addAddress('amalina@distech.com.my');

$body  = "Test from Server <br>";
$body  = "Thank you";

$mail->Subject = 'Test';
$mail->Body = $body;                                    
$mail->isHTML(true); 

if(!$mail->send()) 
{
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} 
else 
{
    echo 'Message has been sent';
}

After processing the process, this is the notification that I've got. It says that the message has been sent . But when I checked my email, there's no email received in the inbox. Is there something wrong with my mail server? And when I tried sending it to a different gmail account, it works. Please help me.

2016-03-17 09:06:23 CLIENT -> SERVER: EHLO 192.168.1.20
2016-03-17 09:06:23 CLIENT -> SERVER: STARTTLS
2016-03-17 09:06:24 CLIENT -> SERVER: EHLO 192.168.1.20
2016-03-17 09:06:24 CLIENT -> SERVER: AUTH LOGIN
2016-03-17 09:06:24 CLIENT -> SERVER: ZGlzdGVjaGt0bkBnbWFpbC5jb20=
2016-03-17 09:06:24 CLIENT -> SERVER: ZGlzdGVjaDE1MTM=
2016-03-17 09:06:25 CLIENT -> SERVER: MAIL FROM:
2016-03-17 09:06:25 CLIENT -> SERVER: RCPT TO:
2016-03-17 09:06:25 CLIENT -> SERVER: DATA
2016-03-17 09:06:26 CLIENT -> SERVER: Date: Thu, 17 Mar 2016 10:06:23 +0100
2016-03-17 09:06:26 CLIENT -> SERVER: To: amalina@distech.com.my
2016-03-17 09:06:26 CLIENT -> SERVER: From: Server
2016-03-17 09:06:26 CLIENT -> SERVER: Subject: Test
2016-03-17 09:06:26 CLIENT -> SERVER: Message-ID:
2016-03-17 09:06:26 CLIENT -> SERVER: X-Priority: 3
2016-03-17 09:06:26 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.10 (https://github.com/PHPMailer/PHPMailer/)
2016-03-17 09:06:26 CLIENT -> SERVER: MIME-Version: 1.0
2016-03-17 09:06:26 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2016-03-17 09:06:26 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2016-03-17 09:06:26 CLIENT -> SERVER:
2016-03-17 09:06:26 CLIENT -> SERVER: Thank you
2016-03-17 09:06:26 CLIENT -> SERVER:
2016-03-17 09:06:26 CLIENT -> SERVER: .
2016-03-17 09:06:27 CLIENT -> SERVER: QUIT Message has been sent

There is nothing in the MAIL FROM:, and no address in the From: header either. So this e-mail will look very suspect to any receiving server. Ie, when Gmail tries to forward it to the distech.com.my domain, that domain's mail server is very likely to reject it. And because there's no sender address, there's nowhere to send a bounce to.

So, in summary, fix the from address and try again.

进入您的 Gmail 帐户设置并在底部,打​​开允许安全性较低的应用程序选项,然后等待大约 15 分钟,然后再次运行您的脚本,然后它应该可以工作了!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM