使用 PHP 在 ubuntu 上使用 localhost 发送电子邮件(可以通过外部邮件服务器)

2 apache-http-server sendmail ubuntu

我在笔记本电脑上安装了 Ubuntu 桌面版 12.04 64 位。我使用这些命令来安装一个简单的 Web 服务器:

apt-get install apache2

apt-get install php5

apt-get install mysql-server
Run Code Online (Sandbox Code Playgroud)

对于我想在本地托管的 Sugar crm,一切正常。然而,发送电子邮件是一项真正的斗争,我尝试了 exim4 sendmail 和 postfix。

我配置并尝试了很多,所以我想告诉你我试图使它工作只会引起混乱。

我是 ubuntu 和命令行的新手,非常感谢有关发送邮件的任何指导!

小智 6

我安装了ssmtp:

sudo apt-get install ssmtp
Run Code Online (Sandbox Code Playgroud)

并在以下位置使用了我的 gmail 凭据:

gksu gedit /etc/ssmtp/ssmtp.conf
Run Code Online (Sandbox Code Playgroud)

.

# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
#root=postmaster
root=****@gmail.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=mail
mailhub=smtp.gmail.com:587

AuthUser=****@gmail.com
AuthPass=****
UseTLS=YES
UseSTARTTLS=YES

# Where will the mail seem to come from?
#rewriteDomain=
rewriteDomain=gmail.com

# The full hostname
#hostname=MyMediaServer.home
hostname=****@gmail.com

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
Run Code Online (Sandbox Code Playgroud)

现在一切正常!