通过PHP从免费的Gmail帐户发送

IMB*_*IMB 1 php email dns gmail dkim

我希望使用我的免费Gmail作为From发件人通过PHP脚本发送电子邮件.如何做到这一点,以便SPF记录有效(好像邮件实际上是从Gmail发送的)?

Sab*_*ari 5

还有许多其他库.他们之中有一些是 :

您可以使用任何这些库使用SMTP从PHP发送邮件

使用带有PHPMailer库的Gmail帐户发送邮件的示例如下:

//include the file
require_once('class.phpmailer.php');

$phpmailer          = new PHPMailer();


$phpmailer->IsSMTP(); // telling the class to use SMTP
$phpmailer->Host       = "ssl://smtp.gmail.com"; // SMTP server
$phpmailer->SMTPAuth   = true;                  // enable SMTP authentication
$phpmailer->Port       = 465;          // set the SMTP port for the GMAIL server; 465 for ssl and 587 for tls
$phpmailer->Username   = "yourname@yourdomain"; // Gmail account username
$phpmailer->Password   = "yourpassword";        // Gmail account password

$phpmailer->SetFrom('name@yourdomain.com', 'First Last'); //set from name

$phpmailer->Subject    = "Subject";
$phpmailer->MsgHTML($body);

$phpmailer->AddAddress($to, "To Name");

if(!$phpmailer->Send()) {
  echo "Mailer Error: " . $phpmailer->ErrorInfo;
} else {
  echo "Message sent!";
}
Run Code Online (Sandbox Code Playgroud)

希望这对你有所帮助