Override Apache From Envelope Email Address On Linux

If you have upgraded your linux server recently and are unable to send email using PHP mail() you might need to override the envelope From address to a valid email format. The default apache from address is usually apache@local.localdomain. Your server might give you an error saying this is not a valid from address. To overcome this error you must specifically override the envelope From address. This is different from the email message header from address. You do this by passing -f parameter in the optional fifth parameter of mail() function. The from address must be in a valid email format.


$to ="some@yahoooo.com";
$subject = "EMAIL TEST";
$email_content = "Just a test. Do not reply";
$header = "From: apache@test.com";
// This is what makes it work. This parameter is passed to 
// sendmail to override the envelope from address
$params = "-f apache@test.com'";

if(mail( $to, $subject, $email_content, $header, $params)) {
    echo 'email sent';
} else {
    echo 'cannot send';
}

Leave a comment

2 Comments.

  1. I really like what you guys are up too. This kind of clevver work and exposure!
    Keep up the excellent wworks guys I’ve incororated you guys to my blogroll.

  2. 18 (Xinhua) — Spanish Civil Guards seized a total of 1.The polling stations opened at 7:00 a.&nbsp,Paul Konerko Jersey; Only enter the number you want to borrow along with the prevailing interest rates (or any low interest rates you think might end up applicable and press your button: you&#8217,Tanner Roark USA Jersey;ll be capable to discover how much your per month repayments will be. Dosage depends upon the prescription medication of the concerned doctor.Earlier, the ministry had planned to