Linux 设置 Ubuntu/Apache/PHP 机器来发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7800492/
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
Setting up a Ubuntu/Apache/PHP machine to send email
提问by D??ng V?n
I am working for a small Ho Chi Minh City company whose only server was just one old small computer. Now just a few months later, we are expanding rapidly and one of the requirements for new users is to require them to verify their email addresses.
我在胡志明市的一家小型公司工作,该公司唯一的服务器只是一台旧的小型计算机。现在仅仅几个月后,我们正在迅速扩张,对新用户的要求之一是要求他们验证他们的电子邮件地址。
There are no special programs on the Ubuntu box, instead the only thing I did on the actual server was re-format the entire hard drive from windows XP and installed Natty Narwhal on it, then install Apache and PHPMYADMIN.
Ubuntu 机器上没有特殊程序,我在实际服务器上所做的唯一一件事就是从 Windows XP 重新格式化整个硬盘并在其上安装 Natty Narwhal,然后安装 Apache 和 PHPMYADMIN。
I would like to have PHP to send out an email to both the user and the administrators as soon as somebody applies for membership. But I have no idea what I need to do to start.
我想让 PHP 在有人申请会员资格后立即向用户和管理员发送电子邮件。但我不知道我需要做什么才能开始。
Any ideas on what I need to set up first would be humbly appreciated; I am not looking for a step by step, just some tips to point me in the right direction.
任何关于我需要首先设置的想法都将不胜感激;我不是在寻找一步一步,只是一些提示我指向正确的方向。
-Duong Van
-Duong Van
回答by ghbarratt
The native mail functionis a good built-in option.
本机邮件功能是一个很好的内置选项。
The mail function is part of the PHP core, but it does require sendmail to be installed on the server.
邮件功能是 PHP 核心的一部分,但它确实需要在服务器上安装 sendmail。
I believe sendmail might already be installed with the packages you have already selected, but you can check for it using the command:
我相信 sendmail 可能已经安装了您已经选择的软件包,但您可以使用以下命令检查它:
dpkg --get-selections | grep sendmail
If that comes up empty, you can install sendmail with:
如果显示为空,您可以使用以下命令安装 sendmail:
sudo apt-get install sendmail
回答by drew010
sudo apt-get install sendmail
will install a copy of sendmail that listens locally. If you install that, then php can use the built in mail()
function. There also won't be a risk of becoming a remote relay if you install like this as well.
sudo apt-get install sendmail
将安装本地侦听的 sendmail 副本。如果你安装了它,那么 php 就可以使用内置mail()
函数了。如果您也这样安装,也不会有成为远程中继的风险。
If you plan on sending mail out to other internet domains, you will need to make sure the IP address of the machine sending mail has a reverse DNS entry (PTR record) set up as well. Most large ISP's will reject your mail if your IP does not have a PTR record or one that points to a generic host (e.g. 1.2.3.3.domain.isp.com). It should reverse to something like mail.yourdomain.com
如果您计划将邮件发送到其他 Internet 域,则需要确保发送邮件的机器的 IP 地址也设置了反向 DNS 条目(PTR 记录)。如果您的 IP 没有 PTR 记录或指向通用主机(例如 1.2.3.3.domain.isp.com),大多数大型 ISP 将拒绝您的邮件。它应该反转为类似 mail.yourdomain.com 的内容
回答by J. Bruni
I recommend installing Postfix MTA to send e-mails out the Ubuntu server:
我建议安装 Postfix MTA 以从 Ubuntu 服务器发送电子邮件:
aptitude install postfix
And using the PHP Mailer class to send e-mails from PHP: http://phpmailer.worxware.com/
并使用 PHP Mailer 类从 PHP 发送电子邮件:http: //phpmailer.worxware.com/
For "fully featured" e-mail services my recipe is:
对于“功能齐全”的电子邮件服务,我的方法是:
Postfix + DKIM-proxy + Dovecot + Roundcube + PHP Mailer + SpamAssassin + proper DNS settings + SSL certificate to enable encrypted connections
Postfix + DKIM-proxy + Dovecot + Roundcube + PHP Mailer + SpamAssassin + 正确的 DNS 设置 + SSL 证书以启用加密连接
(And I prefer NginX as HTTP server...)
(我更喜欢 NginX 作为 HTTP 服务器......)
回答by Tomá? Blatny
sudo apt-get install sendmail
sudo sendmailconfig
The second command was needed for me to run correctly. (it asks about some configuration, just type Y
everytime it asks)
我需要第二个命令才能正确运行。(它询问一些配置,Y
每次询问时只需输入)
回答by FatherKeith
sendmail does the trick. You can configure sendmail to use your regular email smtp account, details are here: http://developernote.com/2012/07/how-i-configured-sendmail-for-php-on-ubuntu-server-12-04/and specifically for gmail here: http://linuxconfig.org/configuring-gmail-as-sendmail-email-relayThere is a bug in the sendmail configuration files which you can read about here: http://linux.koolsolutions.com/2010/10/14/tip-fixing-sendmail-configuration-error/
sendmail 可以解决问题。您可以将 sendmail 配置为使用您的常规电子邮件 smtp 帐户,详细信息在这里:http: //developernote.com/2012/07/how-i-configured-sendmail-for-php-on-ubuntu-server-12-04/专门针对 gmail 在这里:http: //linuxconfig.org/configuring-gmail-as-sendmail-email-relaysendmail 配置文件中有一个错误,您可以在这里阅读:http: //linux.koolsolutions.com /2010/10/14/tip-fixing-sendmail-configuration-error/