简体   繁体   English

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

[英]sending e-mail from mail function php

I can send an e-mail using php mail function. 我可以使用php邮件功能发送电子邮件。 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. 我的印象是,要发送电子邮件,您需要SMTP凭据。 How does this function send emails? 该功能如何发送电子邮件? Which SMTP server does it use? 它使用哪个SMTP服务器? How does it work? 它是如何工作的?

In php.ini, there is a field called SMTP. 在php.ini中,有一个名为SMTP的字段。 It is where you set the SMTP server. 它是您设置SMTP服务器的地方。 I think it defaults to localhost. 我认为默认为localhost。 Other related fields include smtp_port and sendmail_from. 其他相关字段包括smtp_port和sendmail_from。 You use these for a Win32 system. 您将它们用于Win32系统。

you have to configure your server to send emails .. 你必须配置你的服务器发送电子邮件..

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

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找到extension=php_openssl.dll并从该行的开头删除分号,以使SSL为ghost for localhost工作。

in php.ini file find [mail function] and change 在php.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"

Now Open C:\\xampp\\sendmail\\sendmail.ini . 现在打开C:\\xampp\\sendmail\\sendmail.ini Replace all the existing code in sendmail.ini with following code 使用以下代码替换sendmail.ini中的所有现有代码

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

Now you have done!! 现在你做到了!! create php file with mail function and send mail from localhost. 使用邮件功能创建php文件并从localhost发送邮件。

PS: don't forgot to replace my-gmail-id and my-gmail-password in above code. PS:不要忘记在上面的代码中替换my-gmail-idmy-gmail-password 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 例如,如果在php.ini文件中有另一个sendmail_path ,则注释以下行: sendmail_path="C:\\xampp\\mailtodisk\\mailtodisk.exe"

REF : LINK REFLINK

The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server. PHP mail()函数通常通过本地邮件服务器发送,通常由Linux,BSD和OS X平台上的sendmail二进制文件提供,但Windows通常不包括本地邮件服务器。

Using the mail() function can be a lot of work. 使用mail()函数可以做很多工作。 Instead use an external library which greatly simplifies this work for you. 而是使用外部库,这大大简化了这项工作。 One such example is PHPMailer 一个这样的例子是PHPMailer

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

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