[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 yourphp.ini
file (on windows) - or passing a
From
header to themail
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 aFrom
header.
This can
be set with theadditional_headers
parameter, or a default can be set in
php.ini
.Failing to do this will result in an
error message similar toWarning:
mail(): "sendmail_from" not set in
php.ini or custom "From:" header
missing.
TheFrom
header sets
alsoReturn-Path
under Windows.
Related Topics
PHP Domdocument Error Handling
Simplexml_Load_String() Fail to Parse Error
Subtracting a Certain Number of Hours, Days, Months or Years from Date
How to Embed HTML Files in PHP Code
iOS Push Notification Does Not Work When Using Crontab Scheduler
Registry Design Pattern...Good or Bad
Call Python from PHP and Get Return Code
Change Cart Total Price in Woocommerce
I am Confused About PHP Post/Redirect/Get
Allow Users to Download Files Outside Webroot
Verify Valid Date Using PHP's Datetime Class
How to Reset MySQL Pointer Back to the First Row in PHP
How to Add a Watermark to an Existing PDF File Using PHP
Accented Characters in MySQL Table
How to Redefine a Type Hint to a Descendant Class When Extending an Abstract Class
Using Prepared Statement, How I Return the Id of the Inserted Row