通过PHP从免费的Gmail帐户发送 [英] Send from free Gmail account via PHP

查看:264
本文介绍了通过PHP从免费的Gmail帐户发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to send email via PHP script using my free Gmail as the From sender. How can this be done such that the SPF records will be valid (as if the mail was actually sent from Gmail)?

推荐答案

还有很多其他的图书馆。其中一些是:

There are many other libraries as well. Some of them are :

  • http://phpmailer.worxware.com/
  • http://pear.php.net/package/Mail (This is Pear package)
  • https://github.com/denvertimothy/ThriveSMTP
  • http://swiftmailer.org/

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

You can send the mail from PHP using SMTP using any of these libraries

发送的示例使用您的Gmail帐户使用PHPMailer库的邮件将是:

An example of sending mail using your Gmail account with PHPMailer library will be :

//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!";
}

希望这有助于您

这篇关于通过PHP从免费的Gmail帐户发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆