简体   繁体   中英

Sending email in php using localhost

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.

这是我的 php.ini 文件

这是我的 sendmail.php 文件

这是我的 sendmail.ini 文件

Please assist

您的邮件格式错误

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM