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

问题描述:

what is the best way for sending E-mails using php and gmail ?

i found th below link :

sending mail with PHPMailer

but after download PHPMailer form it's site , i could n't find class.phpmailer.php !

would u plz show me a way for sending mail (gmail server and php lan)?

another question is my gmail account has set on smtp / is it ok?

best regards

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

使用PHPMailer发送邮件 p>

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

你会告诉我一种发送邮件的方式(gmail服务器和php lan)吗? p>

另一个问题是我的gmail帐户已设置为smtp / 没关系? p>

最好的问候 p> div>

I suggest you use SwiftMailer with its SmtpTransport, where you specify smtp.gmail.com as SMTP server and specify it to use SSL.

Example:

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

Edit, as requested - here's a full example (untested though):

<?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);

Maybe there is Zend Framework included on your free host?

So you could use Zend Mail: http://framework.zend.com/manual/1.11/en/zend.mail.introduction.html