php 我可以使用 gmail 作为我网站的 smtp 服务器吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12189802/
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
Can I use gmail as smtp server for my website
提问by macha
Hello I am trying to get a website up and running. It is currently hosted on AWS, so I do not have my own smtp server running at this moment. So after reading a few articles, I have understood that we could used gmail as a smtp server.
您好,我正在尝试启动并运行一个网站。它目前托管在 AWS 上,所以此时我没有自己的 smtp 服务器在运行。所以看了几篇文章后,我明白我们可以使用gmail作为smtp服务器。
I wanted to double check if what I read was right, I am going to use smart job board software, can I plug in the values provided by gmail and use that as an smtp server??
我想仔细检查我读到的内容是否正确,我将使用智能工作板软件,我可以插入 gmail 提供的值并将其用作 smtp 服务器吗?
采纳答案by Mihai Iorga
Yes, Google allows connections through their SMTP and allows you to send emails from your GMail account.
是的,Google 允许通过其 SMTP 进行连接,并允许您从 GMail 帐户发送电子邮件。
There are a lot of PHP mail scripts that you can use. Some of the most popular SMTP senders are: PHPMailer(with an useful tutorial) and SWIFTMailer(and their tutorial).
您可以使用很多 PHP 邮件脚本。一些最流行的 SMTP 发件人是:PHPMailer(有一个有用的教程)和SWIFTMailer(和他们的教程)。
The data you need to connect and send emails from their servers are your GMailaccount, your password, their SMTP server(in this case smtp.gmail.com) and port (in this case 465) also you have to make sure that emails are being sent over SSL.
您需要连接并从他们的服务器发送电子邮件的数据是您的GMail帐户、您的password、他们的SMTP server(在这种情况下smtp.gmail.com)和端口(在这种情况下465),您还必须确保电子邮件是通过 SSL 发送的。
A quick example of sending an email like that with PHPMailer:
使用PHPMailer发送类似电子邮件的快速示例:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 465; // SMTP Port
$mail->Username = "[email protected]"; // SMTP account username
$mail->Password = "your.password"; // SMTP account password
$mail->SetFrom('[email protected]', 'John Doe'); // FROM
$mail->AddReplyTo('[email protected]', 'John Doe'); // Reply TO
$mail->AddAddress('[email protected]', 'Jane Doe'); // recipient email
$mail->Subject = "First SMTP Message"; // email subject
$mail->Body = "Hi! \n\n This is my first e-mail sent through Google SMTP using PHPMailer.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
回答by Eric J.
I successfully use the GMail SMTP server.
我成功使用了 GMail SMTP 服务器。
We do have a corporate GMail account, though I don't think that matters. A personal GMail account should suffice.
我们确实有一个公司 GMail 帐户,但我认为这并不重要。个人 GMail 帐户就足够了。
I do not have a PHP samplehowever the following configuration for ASP.Net should provide adequate guidance:
我没有 PHP 示例,但是 ASP.Net 的以下配置应该提供足够的指导:
<mailSettings>
<smtp from="[email protected]">
<network enableSsl="true" host="smtp.gmail.com" port="587" userName="[email protected]" password="mypassword" />
</smtp>
</mailSettings>
If someone has a suitable PHP sample, feel free to edit my answer or post your own.
如果有人有合适的 PHP 示例,请随时编辑我的答案或发布您自己的.
回答by regex
Authentication is required I believe, but I don't see why not. I won't do the research for you, but there are a couple things to look into:
我相信需要身份验证,但我不明白为什么不这样做。我不会为你做研究,但有几件事需要研究:
- Their SMTP server requires TLS encryption and is hosted on a non-standard port (995). You will need to ensure that AWS supports both of these options for SMTP outbound.
- There is probably a cap on emails you can send before being marked as spam. You should research this and ensure it is not beyond your requirements.
- 他们的 SMTP 服务器需要 TLS 加密并托管在非标准端口 (995) 上。您需要确保 AWS 支持这两个 SMTP 出站选项。
- 在被标记为垃圾邮件之前,您可以发送的电子邮件可能有上限。您应该对此进行研究并确保它不会超出您的要求。
回答by regex
You can user PHPMailer classfor this job. And you can easily configure the smtp.
您可以使用PHPMailer 类来完成这项工作。您可以轻松配置 smtp。
An example of configuration
配置示例
if (class_exists(@PHPMailer)) {
$smtp_mail = new PHPMailer();
$smtp_mail->isSMTP();
$smtp_mail->SMTPAuth = true; // enable SMTP authentication
$smtp_mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$smtp_mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$smtp_mail->Port = 465; // set the SMTP port
$smtp_mail->Username = "[email protected]"; // GMAIL username
$smtp_mail->Password = "password"; // GMAIL password
$smtp_mail->From = "[email protected]";
$smtp_mail->FromName = "Name";
$smtp_mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$smtp_mail->WordWrap = 50; // set word wrap
$smtp_mail->AddReplyTo("[email protected]","Name");
$smtp_mail->isHTML(true); // send as HTML
}
回答by sajtdavid
Although you can technically use Gmail as SMTP server, it is not recommended for larger websites. By time you may receive issues like "421 4.7.0 Temporary System Problem" or similar, is it was not designed to be used by an application, rather a single person.
虽然技术上可以使用 Gmail 作为 SMTP 服务器,但不建议将其用于较大的网站。随着时间的推移,您可能会收到类似“421 4.7.0 临时系统问题”或类似的问题,这是否不是为应用程序设计的,而是为一个人设计的。
Related issue for the error message above: Gmail SMTP error - Temporary block?
上述错误消息的相关问题: Gmail SMTP 错误 - 临时阻止?

