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

使用php和gmail发送电子邮件的最佳方式是什么? 我找到了以下链接: 使用PHPMailer发送邮件 但下载PHPMailer后,它的网站,我找不到class.phpmailer.php! 你能告诉我一种发送邮件的方式(gmail服务器和php lan)吗? 另一个问题是我的gmail帐户已经设置为smtp /它可以吗? 最好的祝福     
已邀请:
我建议你使用SwiftMailer和它的SmtpTransport,你可以在其中指定smtp.gmail.com作为SMTP服务器并指定它使用SSL。 例:
$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);
    
也许你的免费主机上有Zend Framework? 所以你可以使用Zend Mail: http://framework.zend.com/manual/1.11/en/zend.mail.introduction.html     

要回复问题请先登录注册