0

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

LostLord
  • 2,279
  • 10
  • 32
  • 32
  • can u show me a full code without using phpmailer with all features such as ssl / port / html body ... – LostLord Jan 30 '11 at 21:13
  • May want to checkout a similar SO question at: http://stackoverflow.com/questions/36079/php-mail-using-gmail – Brian Jan 30 '11 at 21:16

2 Answers2

2

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);
Björn
  • 29,019
  • 9
  • 65
  • 81
  • woul u plz learn me phpmailer or easier way! / because i want to test it in a free host and it seems SwiftMailer size is high... – LostLord Jan 30 '11 at 21:42
  • there is no documentation in phpmailer site / why? how can i use it's project? – LostLord Jan 30 '11 at 21:44
  • i just want send mail (with gmail)/ would u plz write for me a complete code for doing that ? – LostLord Jan 30 '11 at 21:46
  • Here are the PHPMailer examples http://phpmailer.worxware.com/index.php?pg=examples – keatch Jan 30 '11 at 23:04
  • 1
    i read the exampls / but after download the phpmailer there is no class.phpmailer.php file!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!where is that – LostLord Jan 31 '11 at 00:04
0

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

Marc
  • 6,749
  • 9
  • 47
  • 78