2013-06-21 91 views
0

我一直在尝试让PHP发送邮件超过一个月。我正在从000webhost,它工作正常,我的朋友的服务器。PHP邮件返回true(邮件接受发送),但邮件不发送

发送邮件PHP代码是:

$subject = $u.", your infomation"; 
$message = "Your password is ".$p; 
$from = "[email protected]"; 
$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”


等/ 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 

和mail.log:

Jun 9 22:05:07 inspiron-1000 sendmail[24552]: r5A357t5024552: from=www-data, size=144, class=0, nrcpts=1, msgid=<[email protected]>, [email protected] 
Jun 9 22:05:07 inspiron-1000 sm-mta[24553]: r5A357A8024553: from=<[email protected]>, size=367, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=ip6-localhost [127.0.0.1] 
Jun 9 22:05:08 inspiron-1000 sendmail[24552]: r5A357t5024552: [email protected], 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队列状态...

/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 <[email protected]> 
        <[email protected]> 
r5M3HicX023780*  19 Fri Jun 21 22:17 <[email protected]> 
        <[email protected]> 
r5M3BSDF023465  19 Fri Jun 21 22:11 <[email protected]> 
       (Deferred: Connection timed out with alt4.gmail-smtp-in.l.goo) 
        <[email protected]> 
r5M36Tjx023175  19 Fri Jun 21 22:06 <[email protected]> 
       (Deferred: Connection timed out with alt4.gmail-smtp-in.l.goo) 
        <[email protected]> 
r5M33YQf023137*  19 Fri Jun 21 22:03 <[email protected]> 
       (Deferred: Connection timed out with alt4.gmail-smtp-in.l.goo) 
        <[email protected]> 
     Total requests: 5 

回答

0

这是我如何修复它: 安装phpmailer

这里是一个教程how to send mail with PHP mailer

这里是我的代码:

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

function sendmail($to,$subject, $body) 
{ 
    return sendmailfrom($to,"[email protected]","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 = '[email protected]';//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);

0

这还不是全部从mail.log的信息。您看到本地服务器确实接受了您的电子邮件,但没有提及尝试将该电子邮件发送给GMail。您可以从命令行中检查排队等待发送的邮件$ mailq。尽管有更多信息,但该日志文件中还有几行可能。

+0

我增加了MAILQ info – TAAPSogeking

+0

正如您所看到的,您尝试发送的消息正在排队并超时。这可能意味着防火墙阻止了与alt4.gmail-smtp-in.l.goo的连接。再次检查这些日志,并检查sendmail是否配置为向外部发送(它可能已经设置为仅供内部使用)。您也可以尝试[通过telnet连接到该服务器](http://drewsymo.com/how-to/smtp-telnet-example-commands-examples-for-smtp-telnet-testing/),如果失败,这是一个防火墙/连接问题。 – SpenserJ

+0

所以这个问题肯定在sendmail而不是主机? – TAAPSogeking