Page 1 of 1

HELP!!! Google Apps and Swift

Posted: Mon Oct 27, 2008 6:01 pm
by silentszeto
Hi,
I am pretty new to PHP.... and I am running this script locally (from my comp)...
i can't SOLVE the problems i have with this simple script...
I am running this with PHP5
My host is iPower and i use google apps (gmail) to do my emails.
User/Password are edited out

Code: Select all

 
<?
//Load in the files we'll need
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
 $swift = new Swift(new Swift_Connection_SMTP(
    "smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE /*Swift_Connection_SMTP::ENC_TLS*/));
$smtp->setUsername("MYUSER");
$smtp->setpassword("********"); 
$swift = new Swift($smtp);
$message =& new Swift_Message("My subject", "My body");
 
$sent = $swift->send($message, "me@me.com", "myuser@mydomain.com");
echo "Sent to $sent recipients";
?>
 
 
If i dun comment out the /*Swift_connectino_SMTP::ENC_TLS, i get :
Fatal error: Call to a member function setUsername() on a non-object in C:\AppServ\www\swift\test.php on line 7
if i comment out that... i get a much bigger mess...
Fatal error: Uncaught exception 'Swift_ConnectionException' with message 'There was a problem reading line 1 of an SMTP response. The response so far was:<br />[]. It appears the connection has died without saying goodbye to us! Too many emails in one go perhaps? (fsockopen: #0) ' in C:\AppServ\www\swift\lib\Swift\Connection\SMTP.php:250 Stack trace: #0 C:\AppServ\www\swift\lib\Swift.php(306): Swift_Connection_SMTP->read() #1 C:\AppServ\www\swift\lib\Swift.php(217): Swift->command('', 220) #2 C:\AppServ\www\swift\lib\Swift.php(101): Swift->connect() #3 C:\AppServ\www\swift\test.php(6): Swift->__construct(Object(Swift_Connection_SMTP)) #4 {main} thrown in C:\AppServ\www\swift\lib\Swift\Connection\SMTP.php on line 250
Anyone know why???
I tried running on my hosting server (with PHP4)... which is worse... nothing showed.. everything disappeared= not working...

Re: HELP!!! Google Apps and Swift

Posted: Sat Dec 06, 2008 2:41 pm
by eggnogg
im not sure, and if you have fixed your code. i am tangled myself now. the only thing i'd see and change is

$swift = new Swift(ne....

put that in the $smtp, like so

$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", 465);
$smtp->setUsername("...");
$smtp->setpassword("...");

$swift =& new Swift($smtp);


idk, just throwing out possibilities
im also tangled with using this cool mailer

its not very straight forwarding, if you not a php cleric, but still tryin

edit: also, maybe you should add numbers, like th 465 i got up there, and the enc type which im still trying to find how to use

Re: HELP!!! Google Apps and Swift

Posted: Sat Dec 06, 2008 3:16 pm
by eggnogg
$smtp =& new Swift_Connection_SMTP("smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS);

worked

Re: HELP!!! Google Apps and Swift

Posted: Sat Dec 06, 2008 4:21 pm
by Chris Corbyn
Yes, so the problem was that you were trying to make method calls to an object that didn't exist ($smtp). Also, you were creating two instances of the Swift class, rather than one of the SMTP class, then one of the Swift class.

Good to hear you have figured it out now anyway :)