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


  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.