开发者

what is the best way for sending E-mails using php and 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)?

anot开发者_StackOverflowher question is my gmail account has set on smtp / is it ok?

best regards


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜