Warning: mail() [function.mail]: “sendmail_from” not set in PHP.ini or custom “from:” header missing in

Views: 108 Last modified: December 18th, 2011 Comments: 0

Some day you decide to use the email function offered by PHP. Obviously it doesn’t work as expected and instead it throws an error like this:

Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in [PATH TO FILE] on line [LINE NUMBER]

The “From:” header is responsible for showing the name and email address as the source of the email.

PHP wasn’t able to transmit the email. How to solve ?

Option 1: change the php.ini file
Open your php.ini file and locate the following directive:

sendmail_from

You will notice an semicolon(;) in front of it – remove it.

Right now you have to provide an name and email address which will be used for the “From” header each time you sent an email.

sendmail_from = test@localhost

Save the file. Restart your webserver and your done.

Option 2: Add the “from” in PHP
The second option is to add a sender manually. The function “mail” offers an optional fourth parameter: “additional headers”. One of those additional headers is: “From”. It shows the name and email from the sender – who’s name is visible for the receiver ?

The optional header which is required at this moment is “From:”. You might add it with PHP like this:

From: MrXHellboy < name@domain.com > // Without the white-spaces

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

if (mail('name@domain.net', 'Test email', 'Just a test', 'From: MrXHellboy <no-reply@domain.com>')){
    echo 'You\'ve got mail!';
}
?>

Refresh your page and try again.

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 1 vote)
    Bluehost

    Mail this!

    To: From:Sum {0+4} =  
    Anything to add ?

        You must be logged in to post a comment.