Feeling dumb - trouble getting started with swift mailer

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
nbt9p54
Forum Newbie
Posts: 3
Joined: Tue Jun 24, 2008 10:44 pm

Feeling dumb - trouble getting started with swift mailer

Post by nbt9p54 »

Trying to just do a basic mail so I can begin to add this to the things I know how to do --- but I obviously need help can someone help get me on the right track - THANKS

1. <?php
2. require_once "Swift.php";
3. require_once "Swift/Connection/SMTP.php";
4. require_once "Swift/Authenticator/LOGIN.php";
5. $log =& Swift_LogContainer::getLog();
6. $log->setLogLevel(4);
7.
8. $smtp =& new Swift_Connection_SMTP("smtp.gmail.com", 587);
9. $smtp->setUsername("nbt9p54");
10. $smtp->setpassword("mypassword");
11. $smtp->setPort(587);
12. $log =& Swift_LogContainer::getLog();
13. $conn =& new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
14. $conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
15. $log =& Swift_LogContainer::getLog();
16.
17. $swift =& new Swift($conn);
18. $log =& Swift_LogContainer::getLog();
19.
20.
21. $message =& new Swift_Message("My subject", "My body");
22. echo $log->dump(true);
23. $sent = $swift->send($message, "nbt9p54@gmail.com", "nbt9p54@gmail.com");
24. echo "Sent to $sent recipients";
25. ?>


Here is the log and error message
++ Log level changed to 4 ++ Forcing ESMTP mode. HELO is EHLO. ++ Forcing ESMTP mode. HELO is EHLO. ++ Authentication mechanism 'LOGIN' attached. ++ Trying to connect... ++ Trying to connect to SMTP server at 'tls://smtp.gmail.com:465 << 220 mx.google.com ESMTP q18sm11067920pog.13 >> EHLO [127.0.0.1] << 250-mx.google.com at your service, [71.131.35.174] 250-SIZE 28311552 250-8BITMIME 250-AUTH LOGIN PLAIN 250 ENHANCEDSTATUSCODES ++ SMTP extension 'SIZE' reported with attributes [28311552]. ++ SMTP extension '8BITMIME' reported with attributes []. ++ SMTP extension 'AUTH' reported with attributes [LOGIN, PLAIN]. ++ SMTP extension 'ENHANCEDSTATUSCODES' reported with attributes [].
Fatal error: Uncaught exception 'Swift_BadResponseException' with message 'Expected response code(s) [250] but got response [530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://mail.google.com/support/bin/answ ... swer=14257 q18sm11067920pog.13]<h3>Log Information</h3><pre>++ Log level changed to 4 ++ Forcing ESMTP mode. HELO is EHLO. ++ Forcing ESMTP mode. HELO is EHLO. ++ Authentication mechanism 'LOGIN' attached. ++ Trying to connect... ++ Trying to connect to SMTP server at 'tls://smtp.gmail.com:465 << 220 mx.google.com ESMTP q18sm11067920pog.13 >> EHLO [127.0.0.1] << 250-mx.google.com at your service, [71.131.35.174] 250-SIZE 28311552 250-8BITMIME 250-AUTH LOGIN PLAIN 250 ENHANCEDSTATUSCODES ++ SMTP extension 'SIZE' reported with attributes [28311552]. ++ SMTP extension '8BITMIME' reported with attributes []. ++ SMTP extension 'AUTH' reported with attributes [LOGIN, PLAIN]. ++ SMTP extension 'ENHANCEDSTATUSCODES' reported with attributes []. >> MAIL FROM: <nbt9p54@gm in C:\wamp\bin\php\php5.2.5\PEAR\Swift.php on line 250
User avatar
dyluck
Forum Commoner
Posts: 54
Joined: Thu Jun 26, 2008 1:44 pm

Re: Feeling dumb - trouble getting started with swift mailer

Post by dyluck »

Gmail uses SSL encryption... you have to have SSL enabled on your server and any smtp calls from the smtp subdomain (smtp.gmail.com) would have to be ssl://smtp.gmail.com
Also I have not used swift mailer, there may be an option to enable "true" for SMTP that requires SSL and username/passwords for sending emails...

I use phpmailer and it works very well for this type of thing.

Check out this post: viewtopic.php?p=470301#p470301
Post Reply