Link to home
Start Free TrialLog in
Avatar of DReade83
DReade83Flag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP mail keeps sending from "nobody@<server_hostname>", resulting emails to fail anti-spam checks

Any idea how I can stop PHP from emailing from "nobody@<server_hostname>" without enabling PHPsuExec?

I've tried the following but to no avail:

<?
    ini_set("sendmail_from", "noreply@<domain>");
    $strHeaders .= "Return-Path: noreply@<domain>\n\r";
?>

Any help on this topic would be greatly appreciated. Thanks in advance!
Avatar of ncoo
ncoo

If you set the from email in the mail() t

mail( "to@email", "Subject","body", "From: from@email");

http://php.net/mail
ASKER CERTIFIED SOLUTION
Avatar of DReade83
DReade83
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This works for me:

                       $org_var = "Flight Exams";
                        $domain_user = "flightexams@flightexams.com";
                        $emailfrom = "desouthard@hotmail.com";

                        $header  = "MIME-Version: 1.0\n";
                        $header .= "Content-type: text/html; charset=iso-8859-1\n";
                        $header .= "Content-Transfer-encoding: 8bit\n";
                        $header .= "From: ".$org_var." <".$emailfrom.">\n";
                        $header .= "Message-ID: <".md5(uniqid(time()))."@flightexams.com>\n";
                        $header .= "Return-Path: ".$domain_user."\n";
                        $header .= "X-Sender: ".$domain_user."\n";
                        $header .= "X-AntiAbuse: This is a solicited email from - ".$org_var." for an appointment to take an FAA pilot exam.\n";
                        $header .= "X-AntiAbuse: Servername - FlightExams.com\n";
                        $header .= "X-AntiAbuse: User - ".$domain_user."\n";

mail("somebody@hotmail.com", "Subject", $body, $header);
You cannot set Return-Path with the other headers if you are using the PHP mail() command as it uses sendmail.  Do it this way:

$to = 'joe@blow.com';
$subject = 'Lower Spam Scores';
$body = 'Blah, blah, blah';
$headers = 'From: webmaster@example.com' . '\r\n' .
   'Reply-To: webmaster@example.com' . '\r\n' .
   'X-Mailer: PHP/' . phpversion();
$return_path = 'noreply@example.com' ;

mail($to, $subject, $body, $header, '-f $return_path');

Cheers,

RDB


Nuts...

Made a mistake in the mail() command in my post above!  

Should be HEADERS, not header as in:

mail($to, $subject, $body, $headers, '-f $return_path');

RDB
Avatar of DReade83

ASKER

It's OK, '-f' sorted it at the time. Thanks anyway.
Sorry,

I saw the question was still open and thought you did not have an answer.  You should close the question, you can ask for your points back.  It should not be a problem as you found your own solution!

Cheers!  Happy New Year!

RDB
No probs, cheers mate. Happy 2008 to you too. :)
Avatar of modus_operandi
Closed, 500 points refunded.
modus_operandi
EE Moderator