从邮件功能php发送电子邮件

从邮件功能php发送电子邮件

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

问题描述

我可以使用php邮件功能发送电子邮件.其他语言也具有类似的功能.

  mail(收件人,主题,消息,标题,参数) 

给我的印象是,要发送电子邮件,您需要SMTP凭据.此功能如何发送电子邮件?它使用哪个SMTP服务器?如何运作?

解决方案

您必须配置服务器以发送电子邮件..

您可以使用sendmail软件包从localhost发送邮件,sendmail软件包在XAMPP中是内置的.因此,如果您使用的是XAMPP,则可以轻松地从本地主机发送邮件.

例如,您可以为gmail配置 C:\ xampp \ php \ php.ini c:\ xampp \ sendmail \ sendmail.ini 来发送邮件./p>在 C:\ xampp \ php \ php.ini 中找到

,找到 extension = php_openssl.dll 并从该行的开头删除分号,以使SSL适用于gmail本地主机.

在php.ini文件中找到 [邮件功能] 并更改

  SMTP = smtp.gmail.comsmtp_port = 587sendmail_from = [email protected]_path ="\" C:\ xampp \ sendmail \ sendmail.exe \"-t" 

现在打开 C:\ xampp \ sendmail \ sendmail.ini .用以下代码替换sendmail.ini中的所有现有代码

  [发送邮件]smtp_server = smtp.gmail.comsmtp_port = 587error_logfile = error.logdebug_logfile = [email protected]_password =我的Gmail密码force_sender =我的[email protected] 

现在您已经完成了!创建具有邮件功能的php文件并从本地主机发送邮件.

PS:请不要忘记替换上面代码中的 my-gmail-id my-gmail-password .另外,如果您从上方复制设置,请不要忘记删除重复的键.例如,如果在php.ini文件中还有另一个 sendmail_path : sendmail_path ="C:\ xampp \ mailtodisk \ mailtodisk.exe"

,则在下面的行中添加注释

REF : LINK

I can send an e-mail using php mail function. Other languages also have similar functions.

mail(to,subject,message,headers,parameters)

I was under an impression that to send an e-mail you need SMTP credentials. How does this function send emails? Which SMTP server does it use? How does it work?

解决方案

you have to configure your server to send emails ..

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 = [email protected]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Now Open C:\xampp\sendmail\sendmail.ini. Replace all the existing code in sendmail.ini with following code

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=my-gmail-password
[email protected]

Now you have done!! create php file with mail function and send mail from localhost.

PS: don't forgot to replace my-gmail-id and my-gmail-password in above code.Also, don't forget to remove duplicate keys if you copied settings from above. For example comment following line if there is another sendmail_path : sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe" in the php.ini file

REF : LINK

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

07-22 18:34