【问题标题】:what is the best way for sending E-mails using php and gmail?使用 php 和 gmail 发送电子邮件的最佳方式是什么?
【发布时间】:2011-06-18 05:59:44
【问题描述】:

使用 php 和 gmail 发送电子邮件的最佳方式是什么?

我找到了下面的链接:

sending mail with PHPMailer

但是从它的网站下载 PHPMailer 后,我找不到 class.phpmailer.php !

你能告诉我一种发送邮件的方法吗(gmail服务器和php lan)?

另一个问题是我的 gmail 帐户已设置为 smtp / 可以吗?

最好的问候

【问题讨论】:

标签: php email gmail


【解决方案1】:

我建议您使用 SwiftMailer 及其 SmtpTransport,您将 smtp.gmail.com 指定为 SMTP 服务器并指定它使用 SSL。

Example:

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
    ->setPort(465)
    ->setEncryption('ssl')
    ->setUsername('yourname@gmail.com')
    ->setPassword('YOUR_SECRET_PWD');
...

编辑, 根据要求 - 这是一个完整的例子(虽然未经测试):

<?php
require_once "lib/swift_required.php";

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
    ->setPort(465)
    ->setEncryption('ssl')
    ->setUsername('yourname@gmail.com')
    ->setPassword('YOUR_SECRET_PWD');

$mailer = Swift_Mailer::newInstance($transport);

$htmlBody = '<html><body><h1>HTML-mail example!</h1><p>Contents</p></body></html>';
$plainBody = 'Looks like you cannot read HTML-emails? This is alternative content only for you.';

$message = Swift_Message::newInstance('This is the subject of the e-mail')
    ->setFrom(array('yourname@gmail.com' => 'You Name'))
    ->setTo(array('yourfriend@domain.com' => 'Your Friends Name'))
    ->setBody($plainBody)
    ->addPart($htmlBody, 'text/html');

$mailer->send($message);

【讨论】:

  • 请你学我phpmailer或更简单的方法! / 因为我想在免费主机上测试它,而且 SwiftMailer 的大小似乎很高......
  • phpmailer 站点中没有文档/为什么?我如何使用它的项目?
  • 我只想发送邮件(使用 gmail)/请您为我写一个完整的代码吗?
  • 我阅读了示例/但下载 phpmailer 后没有 class.phpmailer.php 文件!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!那在哪里
【解决方案2】:

也许您的免费主机中包含 Zend Framework?

所以你可以使用 Zend Mail: http://framework.zend.com/manual/1.11/en/zend.mail.introduction.html

【讨论】:

    猜你喜欢
    • 2013-02-12
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 2012-09-20
    • 2011-09-07
    • 2010-09-08
    相关资源
    最近更新 更多