CoderZone.org
Pages: 1 « previous     next »
  Print  
Author Topic: Using mail() on certain hosts  (Read 4169 times) Bookmark and Share
Max
Jr. Member
*****
Posts: 75



View Profile WWW
« on: Mar 26, 2011, 08:55:45 am »

I recently acquired a new Debian server and started running into issues with mail(). I found a *LOT* of my outgoing emails sent with the mail() command were being rejected by Yahoo, Hotmail, Comcast, Verizon, etc (and even to my own servers!). The error message in the returned mail was always along the lines of "Sender address rejected", and the sender address was showing up as something like "vu2035.server.servername.com", even though it was being set explicitly in the mail() header string.

"vu2035" is the name of the virtual user under Debian, and "server.servername.com" was, of course, the server itself.

The "cure" for this was simple: use the '-f' command line parameter to set the "from" address, which for some reason wasn't being set properly by PHP running under Debian.

Before:
Code:  
Highlight Mode: (PHP)
  1. $to = 'someone@domain.com';
  2. $headers = '';
  3. $subject = "Sample email subject";
  4. $message = "Sample message text";
  5. $headers = "From: max@max.com\r\n";
  6. // send email
  7. mail($to,$subject,$message,$headers);
 


After:
Code:  
Highlight Mode: (PHP)
  1. $to = 'someone@domain.com';
  2. $headers = '';
  3. $subject = "Sample email subject";
  4. $message = "Sample message text";
  5. $headers = "From: max@max.com\r\n";
  6. // send email
  7. mail($to,$subject,$message,$headers, '-fmax@max.com');
 

Notice the last line. Some setups allow a space between the '-f' and the email address, some don't.

The php mail() page is filled with caveats about using this parameter, so you may need to experiment a bit:


Logged
cuberat
Newbie
*
Posts: 40


View Profile
« Reply #1 on: Mar 26, 2011, 10:54:48 am »

This might be worth a try as well, you could set it with .htaccess at the account level.

http://www.php.net/manual/en/mail.configuration.php#ini.sendmail-from
Logged
Tags: mail reject sender 
Pages: 1
  Print  
 
Jump to: