Page 1 of 1

[SOLVED] Gmail - SMTP

Posted: Tue Mar 06, 2007 10:27 pm
by profphp

Code: Select all

function send_mail($subj, $body)
{
  require("./lib/swift/Swift.php");
  require("./lib/swift/Swift/Connection/SMTP.php");
	$swift = new Swift(new Swift_Connection_SMTP('smtp.gmail.com', 
						     SWIFT_SECURE_PORT, 
						     SWIFT_TLS));
	$swift->authenticate('xxxxx', 'xxxxxx');  

	if (!$swift->hasFailed())
	  {
       $message =& new Swift_Message($subj, $body);



                           //Start a new list

                    $recipients =& new Swift_RecipientList();


                 $recipients->addTo("joe@bloggs.tld"); //or we can just add the address




           $result = $swift->send($message, $recipients, new Swift_Address("xxxxxx", "xxxxx"));

       if (!$result){

           echo "error: ";

             }
	    $swift->close();
	  }
      }
when I ran, it complains about undefined constants... as you can see from the path down, swift is located in additional swift directory, and that's it, your structure is same.
what do you think is going wrong?

PHP Notice: Use of undefined constant SWIFT_SECURE_PORT - assumed 'SWIFT_SECURE_PORT' in /var/www/html/parser/mls_email_utility.php on line 115
PHP Notice: Use of undefined constant SWIFT_TLS - assumed 'SWIFT_TLS' in /var/www/html/parser/mls_email_utility.php on line 116
PHP Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'The SMTP connection failed to start [smtp.gmail.com:0]: fsockopen returned Error Number 0 and Error String 'Failed to parse address "smtp.gmail.com"'' in /var/www/html/parser/lib/swift/Swift/Connection/SMTP.php:277
Stack trace:
#0 /var/www/html/parser/lib/swift/Swift.php(218): Swift_Connection_SMTP->start()
#1 /var/www/html/parser/lib/swift/Swift.php(95): Swift->connect()
#2 /var/www/html/parser/mls_email_utility.php(116): Swift->__construct(Object(Swift_Connection_SMTP))

Posted: Wed Mar 07, 2007 12:10 am
by Chris Corbyn
You appear to be using a mixture of old Swift code with version 3.

http://www.swiftmailer.org/wikidocs

There are files in the download named CRITICAL.ttxt and README which you should have read ;)

For the mostpart, you can use EasySwift to get things working, but although I wrote EasySwift to keep the v2 API which I asumed some people would find easier, people seem to be telling me the new API is easier... you'll probably want to try both and see what you think.

Posted: Wed Mar 07, 2007 12:55 am
by Chris Corbyn
If you're looking for the equivalent (PHP5).

Code: Select all

function send_mail($subj, $body) 
{ 
  require("./lib/swift/Swift.php"); 
  require("./lib/swift/Swift/Connection/SMTP.php"); 
        $smtp = new Swift_Connection_SMTP('smtp.gmail.com', 
                                                     Swift_Connection_SMTP::PORT_SECURE, 
                                                     Swift_Connection_SMTP::ENC_TLS);
        $smtp->setUsername("xxxx");
        $smtp->setPassword("xxxx");
        $swift = new Swift($smtp);   

       $message = new Swift_Message($subj, $body); 



                           //Start a new list 

                    $recipients = new Swift_RecipientList(); 


                 $recipients->addTo("joe@bloggs.tld"); //or we can just add the address 




           $result = $swift->send($message, $recipients, new Swift_Address("xxxxxx", "xxxxx")); 

       if (!$result){ 

           echo "error: "; 

             } 
            $swift->disconnect(); 
          } 
      }

Gmail - SMTP

Posted: Wed Mar 07, 2007 5:49 pm
by profphp
thanks for your help. saved me a lot.

I know how difficult to play around with these authentication, and protocols. You did an amazing job!

But you need to have a better documentation. Those pages lost me a lot. It jumps between versions of swift, version of php, version of EasySwift, and Swift.
It is very important to have a clean, clear, and simple documentation.

Look at those companies that sells worthless piece of crap with the help of good marketing and simple manuals.

then look at the irony, your work is amazing!!! There is no alternative. My boss never worries about money when I want to buy libraries.
There are so many in Windows, ASP, etc. There is nothing for php! :)

Again, I would like to congratulate you for this wonderful work of you, and thanks for your quick help.
Ali

Re: Gmail - SMTP

Posted: Wed Mar 07, 2007 6:50 pm
by hawleyjr
profphp wrote: My boss never worries about money when I want to buy libraries.
I'm sure a nice donation would help ;)

Posted: Thu Mar 08, 2007 1:02 am
by Chris Corbyn
I agree that the current documentation is patchy. Perhaps I should make the Swift 2 and EasySwift links less prominent. The entire wiki is a work in progress but I do make changes to it almost every day :)

I figured that with the combination of the wiki, and the API documentation (in the download) it would probably be enough to get people using it.