views:

663

answers:

5

php
$to = "[email protected]";
$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 [email protected] but still the problem persists... writing the mail script for the first time

Am i doing something wrong? is there a better code or way to go thru this?

Any help will be appreciated

Thank you

+1  A: 

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.

usoban
+1  A: 

First all, check you edited the correct php.ini - add phpinfo(); to your script output diagnostic information, including the location of php.ini. You should also be able to see the configured "sendmail_from" value here too.

Failing that, provide a From header, as indicated by usoban

$hdrs="From: [email protected]";
mail($to, $subject, $body, $hdrs);
Paul Dixon
i have edited the right php.ini file but still there are errors
anand
+1  A: 

If you edited the correct php.ini and it does not reflect your change, you might want to restart your web service, as many environments will only load the php.ini when the server starts.

Ben Reisner
A: 

Rather than setting the form address in php.ini, just send it in the headers like usoban said instead.

This will save you headaches when you host another site on the same setup and forget to set the headers next time.

Ali
A: 

PHP mail() function generates a lot of problems. When you finally get it working on your server, you will notice that your emails end up in spam folders of your users.

I would recommend to send mail using one of those PHP SMTP libraries instead:

warpech