PHP mail() 默认使用什么 SMTP 服务器,有没有更好的选择?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/977592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What SMTP server does PHP mail() use by default, and are there better options?
提问by johnnietheblack
I host my site with GoDaddy , and I use the PHP mail()function at the moment to send form mails from my site. GoDaddy has a 1000 SMTP relay limit per day for form mail stuff, but they swear that with my PHP script that I should not be touching it.
我使用 GoDaddy 托管我的网站,我现在使用 PHPmail()函数从我的网站发送表单邮件。GoDaddy 对表单邮件内容每天有 1000 个 SMTP 中继限制,但他们用我的 PHP 脚本发誓我不应该碰它。
Since
mail()doesn't take SMTP info, does it just automatically use GoDaddy's (or whatever hosting you may be on)?If my site is going to be expecting more than 1000 emails sent out a day (separate instances, not in a loop), should I be using a different method, or is
mail()the right choice?
由于
mail()不接受 SMTP 信息,它是否会自动使用 GoDaddy(或您可能使用的任何主机)?如果我的网站预计每天发送 1000 多封电子邮件(单独的实例,而不是循环发送),我应该使用不同的方法,还是
mail()正确的选择?
回答by Silfverstrom
Php uses by default, the local mail-server. However you can specify this in your php.ini configuration file.
PHP 默认使用本地邮件服务器。但是,您可以在 php.ini 配置文件中指定它。
If you expect to send more email than that, you might want to look into finding a different server to mail from, or alternative hosting
如果您希望发送更多电子邮件,您可能需要考虑寻找不同的服务器来发送邮件,或替代托管
回答by Suresh Kamrushi
Dont use mail() function of php it will send your mail to junk only. Instead use SMTP php mailer function.
不要使用 php 的 mail() 函数,它只会将您的邮件发送到垃圾邮件。而是使用 SMTP php 邮件程序功能。
Why we should use SMTP instead PHP mail():
为什么我们应该使用 SMTP 而不是 PHP mail():
SMTPlog in to an actual account on a mailserver and send the mail through SMTP to another mail server. If the mail server is configured correctly, your mails are sent from an actual account on a mailserver and will not wind up flagged as spam.
SMTP登录到邮件服务器上的实际帐户,并通过 SMTP 将邮件发送到另一个邮件服务器。如果邮件服务器配置正确,您的邮件是从邮件服务器上的实际帐户发送的,并且不会被标记为垃圾邮件。
Mailsent with the mail() function is sent with sendmail in most cases. There is no authentication going on and it will almost always be flagged as spam if you use the "From:" in the extra headers.
邮件与mail()函数发送的和sendmail在大多数情况下发送。没有进行身份验证,如果您在额外的标题中使用“发件人:”,它几乎总是被标记为垃圾邮件。
This is because if you take a look at an original email file in say, gmail, you will see the headers that are sent. You are actually sending from [email protected] and not [email protected] like you had told the mail function to do. If you use SMTP and view the original the email is actually sent from [email protected]
这是因为如果您查看 gmail 中的原始电子邮件文件,您将看到发送的标题。您实际上是从 [email protected] 发送的,而不是像您告诉邮件功能那样发送的 [email protected]。如果您使用 SMTP 并查看原件,则电子邮件实际上是从 [email protected] 发送的
You can download SMTP class from:
您可以从以下位置下载 SMTP 类:
回答by Darryl Hein
On a *nix machine, the PHP mail()function does not support SMTP, but instead uses the sendmail() or other configured mail script on the server. This script can send through an SMTP, but this isn't the easiest way within PHP (unless you already have the script). To use SMTP, I would recommend PHPMailer. I have been using it for a few years now and have been impressed. It supports SMTP along with many other protocols and also has other helpful functionality, such as adding a text only body for an HTML email and creating the proper email headers. You can also extend the class to set defaults, such as the SMTP server and from email/name so you don't have to set these every time you want to send an email. It also does very nice error reporting and debugging.
在 *nix 机器上,PHPmail()函数不支持 SMTP,而是使用服务器上的 sendmail() 或其他配置的邮件脚本。该脚本可以通过 SMTP 发送,但这不是 PHP 中最简单的方法(除非您已经拥有该脚本)。要使用 SMTP,我会推荐PHPMailer。我已经使用它几年了,并给我留下了深刻的印象。它支持 SMTP 以及许多其他协议,还具有其他有用的功能,例如为 HTML 电子邮件添加纯文本正文和创建正确的电子邮件标题。您还可以扩展该类以设置默认值,例如 SMTP 服务器和电子邮件/名称,这样您就不必在每次要发送电子邮件时进行设置。它也做非常好的错误报告和调试。
I would also recommend this class for sending out 1000s of emails. I recently did >5000 in one day with it and had no problems.
我还推荐这门课来发送 1000 封电子邮件。我最近一天用它做了超过 5000 次,没有任何问题。
回答by Chris S
If you need to use an external email server that requires authentication, you will not be able to use the PHP mail() function.
如果您需要使用需要身份验证的外部电子邮件服务器,您将无法使用 PHP mail() 函数。
I recommend using: http://pear.php.net/package/Mail
我推荐使用:http: //pear.php.net/package/Mail
回答by Matt C
mail() does use the setting as defined in the php.ini. Windows servers require an actual smtp server while *nix servers will use whatever mta is installed on the server (if any).
mail() 确实使用 php.ini 中定义的设置。Windows 服务器需要实际的 smtp 服务器,而 *nix 服务器将使用服务器上安装的任何 mta(如果有)。
As others have mentioned, if you do want to use an alternate smtp server, use an alternative library like SwiftMailer. Also you'd want to make sure the smtp server is fast. I have seen slowdowns when using an smtp server like gmail.
正如其他人所提到的,如果您确实想使用备用 smtp 服务器,请使用像 SwiftMailer 这样的备用库。您还需要确保 smtp 服务器速度快。在使用像 gmail 这样的 smtp 服务器时,我看到速度变慢。
GoDaddy uses a Smart SMTP Relay, even on for dedicated servers hosted with GoDaddy. The limit is based on how many emails are going through the Smart relay.
GoDaddy 使用智能 SMTP 中继,甚至适用于由 GoDaddy 托管的专用服务器。该限制基于通过智能中继的电子邮件数量。
If you have a valid reason for needing to send more emails and you can verify that your site isn't spamming and that all of the emails are opt-in, support will increase the limit for you if you give them an estimate of how many emails you need to send out.
如果您有需要发送更多电子邮件的正当理由,并且您可以验证您的网站不是垃圾邮件,并且所有电子邮件都已选择加入,如果您向他们提供估计数量,支持将为您增加限制您需要发送的电子邮件。
回答by Chaya Cooper
Since this is an old post I thought it would be helpful if I updated the answer -
由于这是一篇旧帖子,我认为如果我更新答案会有所帮助 -
This is a lot simpler to do now than it used to be :-) In PHP 4 the PEAR Mail package is typically already installed, and this really simple tutorial shows you the few lines of code that you need to add to your php file http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
现在这比以前要简单得多:-) 在 PHP 4 中,PEAR Mail 包通常已经安装,这个非常简单的教程向您展示了需要添加到 php 文件http的几行代码://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
Most hosting companies list the SMTP settings that you'll need. I use JustHost, and they list theirs at https://my.justhost.com/cgi/help/26(under Outgoing Mail Server)
大多数托管公司都会列出您需要的 SMTP 设置。我使用 JustHost,他们在https://my.justhost.com/cgi/help/26 (在外发邮件服务器下)列出了他们的
回答by Acyra
回答by Kev
If you need to use a third party mail service I'd recommend dropping the use of mail()and replace with the SwiftMailerlibrary. It's a feature rich component (supports authentication, attachments, encryption etc) we've used it in a few places. It's also free and open source.
如果您需要使用第三方邮件服务,我建议您放弃使用SwiftMailer库mail()并替换为SwiftMailer库。这是一个功能丰富的组件(支持身份验证、附件、加密等),我们已经在一些地方使用过它。它也是免费和开源的。

