PHP邮件返回true(消息已接受传递),但未发送消息 [英] PHP mail returns true (Message accepted for delivery), but the message is not sent

查看:130
本文介绍了PHP邮件返回true(消息已接受传递),但未发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让php发送邮件超过一个月。我正在从工作正常的000webhost迁移到我朋友的服务器。

I have been trying get php to send mail for over a month. I am moving from 000webhost, where it worked fine, to my friend's server.

发送邮件的php代码是:

The php code that sends mail is:

$subject = $u.", your infomation";  
$message = "Your password is ".$p;  
$from = "me@gmail.com";  
$headers = "From:" . $from;  
if(mail($e,$subject,$message,$headers))  
$_SESSI ON['message']="message sent";  
else $_SESSION['message']="error";






php.ini中的sendmail路径为 / usr / sbin / sendmail -t -i


the sendmail path in php.ini is "/usr/sbin/sendmail -t -i"

etc / hosts:

etc/hosts:

000.000.000.000 inspiron-1000 inspiron-1000.
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters






和邮件.log:


and the mail.log:

Jun 9 22:05:07 inspiron-1000 sendmail[24552]: r5A357t5024552: from=www-data, size=144, class=0, nrcpts=1, msgid=<201306100305.r5A357t5024552@inspiron-1000.>, relay=www-data@localhost
Jun 9 22:05:07 inspiron-1000 sm-mta[24553]: r5A357A8024553: from=<www-data@inspiron-1000>, size=367, class=0, nrcpts=1, msgid=<201306100305.r5A357t5024552@inspiron-1000.>, proto=ESMTP, daemon=MTA-v4, relay=ip6-localhost [127.0.0.1]
Jun 9 22:05:08 inspiron-1000 sendmail[24552]: r5A357t5024552: to=user@gmail.com, ctladdr=www-data (33/33), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30144, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (r5A357A8024553 Message accepted for delivery)






Ť他是mailq:
MSP队列状态...


this is mailq: MSP Queue status...

/var/spool/mqueue-client is empty
        Total requests: 0
MTA Queue status...
        /var/spool/mqueue (5 requests)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
r5M3LmZV023863*      19 Fri Jun 21 22:21 <www-data@inspiron-1000>
                     <user@gmail.com>
r5M3HicX023780*      19 Fri Jun 21 22:17 <www-data@inspiron-1000>
                     <user@gmail.com>
r5M3BSDF023465       19 Fri Jun 21 22:11 <www-data@inspiron-1000>
                 (Deferred: Connection timed out with alt4.gmail-smtp-in.l.goo)
                     <user@gmail.com>
r5M36Tjx023175       19 Fri Jun 21 22:06 <www-data@inspiron-1000>
                 (Deferred: Connection timed out with alt4.gmail-smtp-in.l.goo)
                     <user@gmail.com>
r5M33YQf023137*      19 Fri Jun 21 22:03 <www-data@inspiron-1000>
                 (Deferred: Connection timed out with alt4.gmail-smtp-in.l.goo)
                     <user@gmail.com>
        Total requests: 5


推荐答案

我已修复它:
安装 phpmailer

这是一个教程如何使用PHP邮件程序发送邮件

这是我的代码:

<?php
require 'PHPMailer-master/class.phpmailer.php';

function sendmail($to,$subject, $body) 
{ 
    return sendmailfrom($to,"myemail@gmail.com","from me", $subject, $body);
}
function sendmailfrom($to, $from, $from_name, $subject, $body) 
{
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = 'smtp.gmail.com';//required for gmail
    $mail->Port = 465; 
    $mail->Username = 'myemail@gmail.com';//the email I want to send from  
    $mail->Password = 'mypassword';  //my password         
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);
    if(!$mail->Send()) return false;
    else return true;
}
?>

每当我想发送邮件时,我都会通过 include() filename.php),然后运行 sendmail($ to,$ subject,$ body);

When ever I want to send mail I include this code, via include("filename.php"), and run sendmail($to,$subject, $body);

这篇关于PHP邮件返回true(消息已接受传递),但未发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆