我可以使用 gmail 作为我网站的 smtp 服务器吗

2022-01-17 00:00:00 email smtp gmail php

您好,我正在尝试建立一个网站并开始运行.它目前托管在 AWS 上,因此我目前没有运行自己的 smtp 服务器.所以看了几篇文章,我明白了我们可以用gmail作为smtp服务器.

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.

我想仔细检查我读的是否正确,我将使用智能工作板软件,我可以插入 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??

推荐答案

是的,Google 允许通过其 SMTP 进行连接,并允许您从您的 GMail 帐户发送电子邮件.

Yes, Google allows connections through their SMTP and allows you to send emails from your GMail account.

有很多 PHP 邮件脚本可供您使用.一些最受欢迎的 SMTP 发件人是:PHPMailer(带有有用的教程)和SWIFTMailer (以及他们的 教程).

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).

从他们的服务器连接和发送电子邮件所需的数据是您的 GMail 帐户,您的 密码,他们的 SMTP 服务器(在本例中为 smtp.gmail.com)和端口(在本例中为 465)你也有确保通过 SSL 发送电子邮件.

The data you need to connect and send emails from their servers are your GMail account, 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.

使用 发送类似电子邮件的简单示例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   = "john.doe@gmail.com"; // SMTP account username
    $mail->Password   = "your.password";        // SMTP account password

    $mail->SetFrom('john.doe@gmail.com', 'John Doe'); // FROM
    $mail->AddReplyTo('john.doe@gmail.com', 'John Doe'); // Reply TO

    $mail->AddAddress('jane.doe@gmail.com', 'Jane Doe'); // recipient email

    $mail->Subject    = "First SMTP Message"; // email subject
    $mail->Body       = "Hi! 

 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.';
    }
?>

相关文章