Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

email

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

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

mail($to, $sub, $msg, "From: **********@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?

like image 366
Ikari Avatar asked Jan 19 '15 14:01

Ikari


People also ask

What is the default SMTP port value set for PHP mail?

Used under Windows only: host name or IP address of the SMTP server PHP should use for mail sent with the mail() function. Used under Windows only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25.

How can I tell if PHP email is enabled?

<? php if ( function_exists( 'mail' ) ) { echo 'mail() is available'; } else { echo 'mail() has been disabled'; } ?> to check if it is sending mail as intended; <?


2 Answers

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

$headers =  'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'From: Your name <[email protected]>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

mail($to, $subject, $body, $headers);
like image 175
fillobotto Avatar answered Oct 07 '22 17:10

fillobotto


Bro it seems that you're using you own PC/localhost/127.0.0.1 server that's why you can't connect to SMTP server. You can only send mail from live server using similar coding with some amendments :) i.e. add one parameter "Header/From".

mail("[email protected]","Answer","Hope You Vote My Answer Up","From: [email protected]");
like image 34
Mohammad Hani Avatar answered Oct 07 '22 18:10

Mohammad Hani