Page 1 of 1

Newbie who feels like a dummie

Posted: Wed Jun 25, 2008 12:16 am
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

Code: Select all

<?php
require_once "Swift.php";
require_once "Swift/Connection/SMTP.php";
require_once "Swift/Authenticator/LOGIN.php";
$log =& Swift_LogContainer::getLog();
$log->setLogLevel(4);
 
$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", 587);
$smtp->setUsername("nbt9p54");
$smtp->setpassword("mypassword");
$smtp->setPort(587);
$log =& Swift_LogContainer::getLog();
$conn =& new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);
$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$log =& Swift_LogContainer::getLog();
 
$swift =& new Swift($conn);
$log =& Swift_LogContainer::getLog();
 
 
$message =& new Swift_Message("My subject", "My body");
 echo $log->dump(true);
$sent = $swift->send($message, "nbt9p54@gmail.com", "nbt9p54@gmail.com");
echo "Sent to $sent recipients";
?>
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

Re: Newbie who feels like a dummie

Posted: Thu Jun 26, 2008 4:33 pm
by dyluck
Maybe I am wrong but don't php mailers have difficulty sending emails from an SMTP that doesn't have either the same isp as the web server or your smtp domain has the same domain and tld as the website you are sending the email from.. Again I could be wrong as I have not tried to send email from gmail or hotmail ect.

Also check out this post for a really good php mailer code that might work for what you are doing.
viewtopic.php?p=470140#p470140

is port 587 the right port for Gmail's smtp?

Good luck!

Re: Newbie who feels like a dummie

Posted: Fri Jun 27, 2008 10:09 am
by dyluck
Oh just an update on this... gmail requires SSL connection... I am not too sure what is in your: SMTP.php file has in it. The Swift_Connection_SMTP() function, does it call SSL??? You may need to look below.
Also if you are running your own webserver, you will need to activate SSL function and uncomment the Extension for SSL in your php.ini file.

Check these lines:

Code: Select all

$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", 587);
$conn =& new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE,
You may need to do do the following:

Code: Select all

$smtp =& new Swift_Connection_SMTP("ssl://smtp.gmail.com", 587);
$conn =& new Swift_Connection_SMTP("ssl://smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE,

Regards