我已经搜索了几篇关于此的帖子,但没有找到。每个人都在使用后缀。但是当我浏览文本时 https://help.ubuntu.com/community/Postfix
What is a Mail Transfer Agent In other words, it's a mail server not a mail client like Thunderbird, Evolution, Outlook, Eudora, or a web-based email service like Yahoo, GMail, Hotmail, Earthlink, Comcast, SBCGlobal.net, ATT.net etc.... If you worked for a company named Acme and owned acme.com, you could provide your employees with email addresses @acme.com. Employees could send and receive email through your computer, but not without your computer running all the time. If all your email addresses are at a domain (@gmail.com, @yahoo.com) you do not own (you don't own Google) or do not host (acme.com) then you do not need this at all.
正如最后一行所说,您不能将其用于 gmail 或 yahoo 以使其在本地主机上工作..!
谁能告诉我如何使用 gmail SMTP 在本地主机上配置邮件服务器?我正在使用 Ubuntu 14。
我之前尝试过的链接没有一个对我有用。在测试下面列出的链接期间没有错误或警告
https://askubuntu.com/questions/314664/sending-php-mail-from-localhost https://askubuntu.com/questions/228938/how-can-i-configure-postfix-to-send-all-email-through-my-gmail-account https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/ https://easyengine.io/tutorials/mail/postfix-debugging/
最佳答案
请按照以下步骤从 Ubuntu/Linux 上的 localhost 通过 gmail 发送邮件:-
为此,您需要在 Linux/Ubuntu 服务器上安装 msmtp
。
Gmail 使用 https://(超文本安全),因此您需要安装 ca-certificates
~$ sudo apt-get install msmtp ca-certificates
安装 msmtp
包需要几秒钟。
现在您必须使用 gedit 编辑器创建配置文件(msmtprc
)。
~$ sudo gedit /etc/msmtprc
现在您必须在 gedit 中复制并粘贴以下代码(您使用上述命令创建的文件)
defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
account default
host smtp.gmail.com
port 587
auth on
user MY_GMAIL_ID@gmail.com
password MY_GMAIL_PASSSWORD
from MY_GMAIL_ID@gmail.com
logfile /var/log/msmtp.log
不要忘记将 MY_GMAIL_ID 替换为您的“gmail id”,将 MY_GMAIL_PASSWORD 替换为您的“gmail 密码"在上面的代码行中。
现在创建 msmtp.log
为
~$ sudo touch /var/log/msmtp.log
你必须让任何人都可以读取这个文件
~$ sudo chmod 0644 /etc/msmtprc
现在启用 sendmail 日志文件可写
~$ sudo chmod 0777 /var/log/msmtp.log
您的 gmail SMTP 配置现已准备就绪。现在发送一封测试邮件作为
~$ echo -e "Subject: Test Mail\r\n\r\nThis is my first test email." |msmtp --debug --from=default -t MY_GMAIL_ID@gmail.com
请检查您的 Gmail 收件箱。
现在,如果您想从本地主机使用 php 发送电子邮件,请按照以下说明操作:-
打开并编辑php.ini
文件
~$ sudo gedit /etc/php/7.0/apache2/php.ini
您必须在 php.ini
文件中设置 sendmail_path。
使用
检查您的 SMTP 路径~$ which msmtp
你会得到这样的/usr/bin/msmtp
。
在 php.ini
中搜索 sendmail_path
并编辑如下
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/bin/msmtp -t
请仔细检查第 3 行 sendmail_path
之前没有分号。
现在保存并退出 gedit。现在是时候重新启动您的 apache
~$ sudo /etc/init.d/apache2 restart
现在从 http://in2.php.net/manual/en/function.mail.php 创建一个带有邮件功能的 php 文件.
做测试并享受!
关于PHP+Ubuntu 使用gmail form localhost发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33969783/