phpmailer - 我可以在没有 Gmail 的情况下使用本地主机通过 PHP 邮件程序发送电子邮件吗?
问题描述
我可以在不使用 Gmail 的情况下使用本地主机通过 PHP 邮件程序发送电子邮件吗?或使用我的本地主机的任何其他电子邮件服务,如 Hotmail、Outlook?
解决方案
是的,这实际上是使用 PHPMailer 发送的最佳方式。你需要两件事:
- 允许出站 SMTP 的托管服务提供商。大量提供商默认阻止 SMTP,但您可能会发现他们会根据请求删除阻止 (scaleway.com),提供替代服务 (AWS),这也是可以接受的。
- 本地安装的邮件服务器。如果你在 Linux 上,像 postfix 这样的东西是一个不错的选择。
然后它的工作方式是这样的:
localhost
像往常一样编写您的 PHPMailer 脚本,但通过 SMTP(而不是通过mail()
)传递- 将您的邮件服务器配置为充当“完整”邮件服务器,尝试直接传递邮件,或充当“智能主机”以通过其他服务(例如 gmail 或 mailgun)进行中继。
The main advantages of this approach are:
- Perceived performance: your message submissions will appear to be instant, so it's great for things like contact forms
- Reliability: if your message can't be delivered immediately, the local mail server will automatically take care of queuing and redelivery attempts, in a way that is far more efficient than you would ever achieve if you handled that within your own application.
As with many things, with great power comes great responsibility, and you will have to deal with bounce handling, blacklisting, inbound filtering (or just block it), etc. It's probably not worth doing all this for a simple contact form, but if you have an application that generates a reasonable amount of email traffic (signups, password resets, notifications, etc), it's a great way to go.
推荐阅读
- mysql - MySQL(ActiveRecord)计算日期列在分组月份和年份之前或之前的行数
- javascript - 为什么 `forEach.call` 不通过类移除遍历每个节点?
- javascript - 用于 Web 的 Firebase 电话身份验证的工作示例?
- typescript - 由于存在 connectRouter 和 persistReducer,createStore 抛出未知错误
- google-sheets - 两个单元格的条件格式
- html - Flex 表格列宽适合内容
- c# - 如何用 using 语句包围对动态对象的每次调用?
- docker - 如何将日志从 jwilder/nginx-proxy docker 映像发送到 logstash?
- c# - 使用“Visual Studio 安装程序”创建的安装程序安装应用程序后未打开应用程序
- math - 天才数学工具:如何将分数答案显示为小数?