Sending email in php using localhost

两盒软妹~` 提交于 2019-12-08 15:33:42

问题


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.

Please assist


回答1:


Your mail format is wrong

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



回答2:


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);



来源:https://stackoverflow.com/questions/42001769/sending-email-in-php-using-localhost

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!