Php send mail code not working

phpsendmail

$to = "jijodasgupta@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
  echo("pMessage successfully sent!/p");
} else {
  echo("pMessage delivery failed.../p");
}

Wrote a basic php sendmail code that but it gives me the following error:

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or
custom "From:" header missing in C:\xampp\htdocs\mail.php on line 5
Message delivery failed…

I changed the “php.ini file and put sendmail_from=jijodasgupta@gmail.com but still the problem persists.
Writing the mail script for the first time.

Am I doing something wrong? Is there a better way to do this?

Best Solution

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.