smtp auth problems

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
miztiik
Forum Newbie
Posts: 4
Joined: Fri Sep 07, 2007 1:19 am

smtp auth problems

Post 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";
miztiik
Forum Newbie
Posts: 4
Joined: Fri Sep 07, 2007 1:19 am

Post by miztiik »

Code: Select all

Call to undefined method: swift->attachauthenticator()
This is the error i am getting
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
miztiik
Forum Newbie
Posts: 4
Joined: Fri Sep 07, 2007 1:19 am

Post 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";

?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
miztiik
Forum Newbie
Posts: 4
Joined: Fri Sep 07, 2007 1:19 am

Post by miztiik »

but i am able to send emails thru phpmailer, from gmail and to gmail server. so i guess they have that functionality
chuckl
Forum Commoner
Posts: 61
Joined: Wed May 23, 2007 7:36 am

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :)
Post Reply