2

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 PHPMailer();
$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..

Jonah Katz
  • 5,230
  • 16
  • 67
  • 90

3 Answers3

2

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.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • From the command line I can type `mail *****@****.com blah blah` and it successfully sends.. – Jonah Katz Sep 07 '11 at 21:42
  • Then look at the server's logs and see what happens to those PHP-initiated mails after they enter the server's queue. – Marc B Sep 07 '11 at 21:47
  • Thats the problem, the queue is empty so it must be that my phpmailer isnt set up properly. – Jonah Katz Sep 07 '11 at 21:48
  • I think i just fond the issue. I disabled errors so i didnt spot this earlier.. but in my log, i have the error `'PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone settings....` Do you know what this is? – Jonah Katz Sep 07 '11 at 21:50
  • That's just a warning, not an error. It wouldn't affect mail sending. You need to check the mail server's logs, to see what happened to the email AFTER php handed it over. Basically, you've successfully dropped your letter into the mailbox. Now you have to hassle the post office to find out where the letter is. – Marc B Sep 08 '11 at 15:24
0

Make sure your server allows for you to send as the user that you set as the FromName

Naftali
  • 144,921
  • 39
  • 244
  • 303
0

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 ;)

Erik
  • 3,777
  • 21
  • 27