使用localhost在php中发送电子邮件

I am having a bit of a problem getting to send an email from the localhost and kindly need your help. This is the error message I have been getting:

Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\email\send_mail.php on line 22.

This is my php.ini file

This is my sendmail.php file

This is my sendmail.ini file

Please assist

Your mail format is wrong

mail($email_address,$subject,$msg,$header);

To send email using localhost you need to configure localhost to send emails.

The followings steps are to send email using localhost with xampp and sendmail

You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP. So if you are using XAMPP then you can easily send mail from localhost.

for example you can configure C:\xampp\php\php.ini and c:\xampp\sendmail\sendmail.ini for gmail to send mail.

in C:\xampp\php\php.ini find extension=php_openssl.dll and remove the semicolon from the beginning of that line to make SSL working for gmail for localhost.

in php.ini file find [mail function] and change

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Replace all the existing code in sendmail.ini with following code

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=your-gmail-id@gmail.com
auth_password=your-gmail-password
force_sender=your-gmail-id@gmail.com
Then you are done :)

remember to restart the server using the XAMMP control panel so the changes take effect. Happy coding :)

By the way your mail function is incorrect

it should be

mail($to,$subject,$message,$headers);