PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Oct 23, 2019 11:37 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Using Gmail SMTP
PostPosted: Thu Mar 03, 2011 1:21 pm 
Offline
Forum Commoner

Joined: Thu Feb 21, 2008 3:16 pm
Posts: 75


Top
 Profile  
 
 Post subject: Re: Using Gmail SMTP
PostPosted: Thu Mar 03, 2011 5:40 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine
Syntax: [ Download ] [ Hide ]

    <?php

    require_once 'lib/swift_required.php';

    // create the mail transport using the 'newInstance()' method

    $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'sslv3')
        ->setUsername('sleepydad@gmail.com')
        ->setPassword('sleepydadpassword');



    // create the mailer using the 'newInstance()' method
    $mailer = Swift_Mailer::newInstance($transport);


    // create a simple message using the 'newInstance()' method
    $message = Swift_Message::newInstance()
        ->setSubject('Testing Swift Mailer')
        ->setFrom(array('us@yahoo.com' => 'us'))
        ->setTo(array('sleepydad@sleepydad.com' =>' them'))
        ->setBody('Hey, how are you? I am sending you a message with the cool Swift Mailer library');

    if ($mailer->send($message)) {
        echo 'The message was sent successfully!';
    } else {
        echo 'Error sending email message';
    }
 


works for me.

Obviously I replaced addresses and login info with my own while testing, but also I had to set encryption kind (third argument to Swift_SmtpTransport::newInstance() as I mentioned in the other thread) to sslv3 (sslv2 seems to be no longer supported at the gmail's end).

Another thing to note is that yahoo from address will be replaced by the address you use to access gmail - and for a good reason.


Top
 Profile  
 
 Post subject: Re: Using Gmail SMTP
PostPosted: Thu Mar 03, 2011 6:02 pm 
Offline
Forum Commoner

Joined: Thu Feb 21, 2008 3:16 pm
Posts: 75
Thanks as always, Weirdan. I'll give it a try.


Top
 Profile  
 
 Post subject: Re: Using Gmail SMTP
PostPosted: Thu Mar 03, 2011 6:48 pm 
Offline
Forum Commoner

Joined: Thu Feb 21, 2008 3:16 pm
Posts: 75


Top
 Profile  
 
 Post subject: Re: Using Gmail SMTP
PostPosted: Thu Mar 03, 2011 8:01 pm 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 5978
Location: Odessa, Ukraine


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group