[PHP Warning: Mail(): " Sendmail_From" Not Set in PHP.Ini or Custom "From:" Header Missing

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

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, $subject, $body, $headers);

mail() not set in php.ini or custom From: header missing error

Solution : You need a SMTP Server to send emails using php because mail() function requires a MTA(Mail Transfer Agent)
to work and it will not work if you use a local server like XAMPP.

1.You Can Setup SMTP on XAMPP locally .. see this question for more info How to setup mail in XAMPP locally?

2.You can use PHPMailer class at https://github.com/PHPMailer/PHPMailer it allows you to use the mail function or use a SMTP server transparently

3.Use Swift mailer https://swiftmailer.symfony.com/docs/introduction.html

SMTP server response: 530 5.7.0 Must issue a STARTTLS command first

First, make sure you PHP installation has SSL support (look for an "openssl" section in the output from phpinfo()).

You can set the following settings in your PHP.ini:

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");

Error on sending mail with XAMPP

Make sure you have stmp server configured in your xampp and running.

Try enclosing the sendmail_from value in quotes

sendmail_from = "from@example.com"

php send mail code not working

additional_headers (optional)

String to be inserted at the end of
the email header.

This is typically used to add extra
headers (From, Cc, and Bcc). Multiple
extra headers should be separated with
a CRLF (\r\n).

Note: When sending mail, the mail must
contain a From header. This can be set
with the additional_headers parameter,
or a default can be set in php.ini.
Failing to do this will result in an
error message similar to Warning:
mail(): "sendmail_from" not set in
php.ini or custom "From:" header
missing. The From header sets also
Return-Path under Windows.

I hope that helps.

Error with PHP mail() function

When sending a mail, a From header (i.e. the address from which the mail is sent) has to be set.

This can be set either :

  • setting a value for sendmail_from in your php.ini file (on windows)
  • or passing a From header to the mail function -- in the fourth parameter.


The message you posted indicates you've done none of those -- and that you must do at least one, to specify a From header.

Quoting the Note in the "*additional_headers*" section of the manual page of mail() :

When sending mail, the mail must
contain a From header.
This can
be set with the additional_headers
parameter, or a default can be set in
php.ini.

Failing to do this will result in an
error message similar to Warning:
mail(): "sendmail_from" not set in
php.ini or custom "From:" header
missing.

The From header sets
also Return-Path under Windows.



Related Topics



Leave a reply



Submit