Page 1 of 1
smtp auth problems
Posted: Fri Sep 07, 2007 1:33 am
by miztiik
i need to sent mail using the gmail
what am i doing wrong here. could someone help me around
Code: Select all
require_once "Swift.php";
require_once "Swift/Connection/SMTP.php";
require_once "Swift/Authenticator/LOGIN.php";
$smtp =& new Swift(new Swift_Connection_SMTP("ssl://smtp.gmail.com",465, SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS));
$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
$smtp->setUsername("Email@domai.tld");
$smtp->setPassword("email_pass");
$smtp->setTimeout(2);
$swift =& new Swift($smtp);
$message =& new Swift_Message("My subject", "My body");
if ($swift->send($message, "sender@gmail.com", "reciever@gmail.com"))
{
echo "Sent";
}
else echo "Failed";
Posted: Fri Sep 07, 2007 2:10 am
by miztiik
Code: Select all
Call to undefined method: swift->attachauthenticator()
This is the error i am getting
Posted: Fri Sep 07, 2007 4:23 am
by Chris Corbyn
You've assigned $smtp to "new Swift()" instead of "new Swift_Connection_SMTP()".
Code: Select all
$smtp =& new Swift_Connection_SMTP("smtp.gmail.com",465, SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS);
$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
$smtp->setUsername("Email@domai.tld");
$smtp->setPassword("email_pass");
$smtp->setTimeout(2);
$swift =& new Swift($smtp);
Don't put the ssl:// on there neither.
Posted: Sun Sep 09, 2007 11:23 pm
by miztiik
i have made the changes as suggested by you, stil i am gettin this error.
Code: Select all
Fatal error:
Uncaught Error of type [swift_connectionexception] with message [The SMTP connection failed to start [tls://smtp.gmail.com]: fsockopen returned Error Number 0 and Error String 'Success']
@0 swift::swift() in /home/myDir/public_html/swiftmail/SwiftMailer.php on line 28
@1 swift::connect() in /home/myDir/public_html/swiftmail/Swift.php on line 109
in /home/myDir/public_html/swiftmail/Swift/Errors.php on line 99
here is the full code that i am using now
Code: Select all
<?php
//Load in the files we'll need
require_once "Swift.php";
require_once "Swift/Connection/SMTP.php";
require_once "Swift/Authenticator/LOGIN.php";
//Start Swift
//$conn->attachAuthenticator(new Swift_Authenticator_LOGIN());
$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", SWIFT_SMTP_PORT_SECURE, SWIFT_SMTP_ENC_TLS);
$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
$smtp->setUsername("uid@domain.tld");
$smtp->setPassword("Uid_p@ssw0rd");
$smtp->setTimeout(2);
$swift =& new Swift($smtp); /* Line 28 where it shows the error*/
//$swift =& new Swift($conn);
//Create the message
$message =& new Swift_Message("My subject", "My body");
//Now check if Swift actually sends it
if ($swift->send($message, "2@gmail.com", "fr0m@gmail.com"))
{
echo "Sent";
$swift->disconnect();
}
else echo "Failed";
?>
Posted: Mon Sep 10, 2007 6:57 am
by Chris Corbyn
That error is a bug with certain versions of PHP. fsockopen() is failing to connect, but the "success" status shouldn't be there because there's no socket created. It's an implementation detail issue. You would be best advised to speak to your host. It may be that TLS is not enabled in their version of PHP.
Posted: Sat Sep 15, 2007 4:50 am
by miztiik
but i am able to send emails thru phpmailer, from gmail and to gmail server. so i guess they have that functionality
Posted: Sat Sep 15, 2007 7:01 am
by chuckl
You are able to send mail through gmail using TLS and phpMailer?
PhpMailer also uses fsockopen, so it's not that if it's the same server. Could I suggest you remove the 2 second timeout you've set?
It defaults to 15sec, and I can't see that setting it to 2sec serves any useful purpose other than to potentially cause problems and error messages like the one you are getting.
Posted: Sat Sep 15, 2007 12:37 pm
by Chris Corbyn
chuckl wrote:You are able to send mail through gmail using TLS and phpMailer?
PhpMailer also uses fsockopen, so it's not that if it's the same server. Could I suggest you remove the 2 second timeout you've set?
It defaults to 15sec, and I can't see that setting it to 2sec serves any useful purpose other than to potentially cause problems and error messages like the one you are getting.
Thanks I completely missed that. 2 seconds is not a lot, especially on the first request because you rely on the name servers responding in time, followed by the time to open a socket on a potentially busy server.
I apologise if I seem a bit vacant lately with respect to support requests. I move out to Australia in just under two weeks and I'm bogged down with work I have to get finished

I appreciate the contributions of other members on this forum
