Saitama Saitama - 7 months ago 160
PHP Question

[PHP Warning: mail(): " sendmail_from" not set in php.ini or custom "From:" header missing

I am trying to use PHP's mail() function to send a test mail.

$to = "gourab@seewitheie.com";
$sub = "Php Mail";
$msg = "Test Message From PHP";

mail($to, $sub, $msg, "From: gourabnag12@gmail.com");


When I try to debug it through
step
in
phpdbg
, it shows the message:

[PHP Warning: mail(): " sendmail_from" not set in php.ini or custom "From:" header
missing in C:/xampp/htdocs/tinyProj/mail.php on line 4]


I cannot understand why?

Answer

It seems your From header is not correctly formatted. Try this instead:

$headers =  'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'From: Your name <info@address.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

mail($to, $object, $body, $headers);
Comments