使用localhost在php中发送电子邮件 [英] Sending email in php using localhost

查看:525
本文介绍了使用localhost在php中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从本地主机发送邮件时遇到了一些问题,并且需要您的帮助。这是我收到的错误消息:


警告:mail():sendmail_from未在php.ini中设置或自定义发件人:
头文件丢失在第22行的C:\xampp\htdocs\email\send_mail.php中。








请协助

解决方案

要使用localhost发送电子邮件,您需要配置localhost以发送电子邮件。



以下步骤是使用localhost发送电子邮件, xampp sendmail



你可以使用sendmail包从localhost发送邮件,在XAMPP中建立sendmail包。因此,如果您正在使用XAMPP,那么您可以轻松地从localhost发送邮件。



例如,您可以配置 C:\ xampp \ php \\ \\ _ \\ n \\ _php.ini c:\ xampp \ sendmail \ sendmail.ini 用于gmail发送邮件。



C:\ xampp \ php \ php.ini中找到extension = php_openssl.dll 并从头开始删除分号该行使gmail为localhost工作。



in php.ini file find [邮件功能] 并更改

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

使用以下代码替换sendmail.ini中的所有现有代码

  smtp_server = smtp.gmail.com 
smtp_port = 587
error_logfile = error.log
debug_logfile = debug.log
auth_username =您的-gmail-id@gmail.com
auth_password = your-gmail-password
force_sender=your-gmail-id@gmail.com
然后你就完成了:)

切记使用XAMMP控制面板重新启动服务器,以使更改生效。快乐编码:)



顺便说一句,你的邮件功能不正确



应该是

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


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

解决方案

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

这篇关于使用localhost在php中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆