Php send zip code not working

$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 the php sendmail base code, but it gives me the following error:

Warning: mail () [function.mail]: "sendmail_from" is not set in php.ini or the custom header "From:" is not in C: \ xampp \ htdocs \ mail.php on line 5 Error sending messages ...

I modified the file `` php.ini and placed sendmail_from=jijodasgupta@gmail.com , but the problem still persists. Writing a mail script for the first time.

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

+4
source share
6 answers

Additional_documents (optional)

The string to be inserted at the end of the email header.

This is usually used to add additional headers (From, Cc, and Bcc). multiple optional headers must be separated by CRLF (\ r \ n).

Note. When sending mail, mail should contain the From header. This can be set with the Additional_headers parameter, or by default can be set in php.ini. Otherwise, this will result in an error message similar to the warning: mail (): "sendmail_from" is not set in php.ini or the custom header "From:" is missing. From header sets also return the path under Windows.

I hope this helps.

+2
source

First of all, check that you edited the correct php.ini - add phpinfo(); to your diagnostic output script information, including the location of php.ini. Here you can also see the configured value "sendmail_from".

Otherwise, specify the From header as indicated by usoban

 $hdrs="From: jijodasgupta@gmail.com "; mail($to, $subject, $body, $hdrs); 
+1
source

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

+1
source

I ran into the same problem and it ended up using my server account@servername as the email address, although I specified my own in the headers.

The answer I found somewhere else was to add the 5th parameter to the mail call in order to force the system to use the email address I specified:

 $from = ' fromemail@domain.com ' $xheaders = "From: " . $from . " <" . $from . ">\n"; $i = mail("$useremail","$subject","$content",$xheaders,'-f fromemail@domain.com '); 
+1
source

Instead of specifying the form address in php.ini, just send it to the headers, for example, instead of usoban.

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

0
source

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

I would recommend sending mail using one of these PHP SMTP libraries:

0
source

All Articles