Im trying to send email through a Qmail server using phpmailer. After sending, i get the message "meesage was sent" but no message is every received.. Heres my code:
<?php
require("class.phpmailer.php");
$name = "Purchase Form";
$email_subject = "New Purchase Ticket";
$body = NULL;
foreach ($_REQUEST as $field_name => $value){
if (!empty($value)) $body .= "$field_name = $value\n\r";
}
$mail = new PHPMaile开发者_高级运维r();
$mail->IsQmail();
$mail->FromName = $name;
$mail->AddAddress('*******@*********', 'Purchase Ticket');
$mail->Body = $body;
$mail->IsHTML(false);
$mail->Subject = $email_subject;
if(!$mail->Send())
{ echo "didnt work";
}
else {echo "Message has been sent";}
?>
From the command line I can type mail *****@****.com blah blah
and it successfully sends..
Check your mail server's log. Is the server active? Is it handling the mail queue? Did it try sending the message? Did the message bounce? Is the message stuck in the queue?
Just because PHPMailer says it worked doesn't mean anything actually hit the wire. All that means is that PHPMailer successfully handed the email over to the SMTP server. After that, it's utterly out of PHPMailer's hands. Since everything from the PHP side seems to have worked, you'll have to move the investigation down to the next stage of the process, which is the SMTP server.
Make sure your server allows for you to send as the user that you set as the FromName
I think it is a CR/LF problem, which is a known Bug in php for about four years and -as far as I know- hasn't been fixed up to now:
http://bugs.php.net/bug.php?id=15841
The generated Email isn't valid (explanation can be found here: http://cr.yp.to/docs/smtplf.html ), due to using a non-RFC-conform linebreak-format. Other MTA like sendmail and postfix correct this problem automatically; qmail doesn't.
You can either: write correct mails with php (lol), or ask your qmail-administrator to use the QmailScanner ( http://qmail-scanner.sourceforge.net/ ), which is doing this job too.
The best solution would be to deinstall php and use perl in the future duck ;)
精彩评论