简体   繁体   English

使用本地主机在php中发送电子邮件

[英]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.警告:mail(): "sendmail_from" 未在 php.ini 中设置或自定义 "From:" 标题在第 22 行的 C:\\xampp\\htdocs\\email\\send_mail.php 中丢失。

这是我的 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.要使用 localhost 发送电子邮件,您需要配置 localhost 以发送电子邮件。

The followings steps are to send email using localhost with xampp and sendmail以下步骤是使用本地主机与xamppsendmail发送电子邮件

You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP.您可以使用 sendmail 包从本地主机发送邮件,XAMPP 中内置了 sendmail 包。 So if you are using XAMPP then you can easily send mail from localhost.因此,如果您使用 XAMPP,那么您可以轻松地从本地主机发送邮件。

for example you can configure C:\\xampp\\php\\php.ini and c:\\xampp\\sendmail\\sendmail.ini for gmail to send mail.例如你可以配置C:\\xampp\\php\\php.inic:\\xampp\\sendmail\\sendmail.ini为 gmail 发送邮件。

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.C:\\xampp\\php\\php.ini find extension=php_openssl.dll并从该行的开头删除分号,以使 SSL 为 localhost 的 gmail 工作。

in php.ini file find [mail function] and changephp.ini文件中找到[mail function]并更改

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用以下代码替换 sendmail.ini 中的所有现有代码

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.请记住使用 XAMMP 控制面板重新启动服务器,以使更改生效。 Happy coding :)快乐编码:)

By the way your mail function is incorrect顺便说一下你的邮件功能不正确

it should be它应该是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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