Page 1 of 1

[SOLVED] Trying to get SwiftMailer Working...

Posted: Wed Mar 07, 2007 2:33 pm
by seodevhead
Looks like a handy little library.. but am having some difficulty getting it to work.

Getting this error:

Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/user/public_html/swiftlib/Swift.php on line 34


I uploaded "swift" (previously 'lib') folder to /public_html/ and am using the following modified code from the "simple email tutorial":

Code: Select all

//Load in the files we'll need
require_once ('../swift/Swift.php');
require_once ('../swift/Swift/Connection/SMTP.php');
 
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("smtp.mysite.com"));
 
//Create the message
$message =& new Swift_Message("My subject", "My body");
 
//Now check if Swift actually sends it
if ($swift->send($message, "me@mysite.com", "me2@mysite.com")) echo "Sent";
else echo "Failed";
 
Using PHP 4.4.4.

File including code above is located in /public_html/testmail/ ... thus the ../swift/ path traversal is correct. :)

Any ideas what is going on here? Thanks.

Posted: Wed Mar 07, 2007 2:40 pm
by Luke
looks like you are trying to use the php5 version of swiftmailer. download the version for php4

Posted: Wed Mar 07, 2007 3:05 pm
by seodevhead
Wow... good catch Ninja. I'm an idiot. I need to read things more carefully. Thanks for the heads up.. It works now! :)

Posted: Thu Mar 08, 2007 2:40 pm
by $var
Hello,

I am also having some difficulties getting this to work.

It is PHP5 on my server and the PHP 5 .zip, however, it is echoing "failed" when i try to send it.
I echoed the $message variable, and it prints out this (which probably tells you nothing):

Catchable fatal error: Object of class Swift_Message could not be converted to string in /home/.ufowasherkiln/hcw/honeycombworldwide.com/mailer/index.php on line 15

(the index.php i am using is in the lib folder that i renamed to mailer)
-----------

Code: Select all

//Load in the files we'll need
require_once "Swift.php";
require_once "Swift/Connection/SMTP.php";
 
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("mail.meaghanbent.com"));
 
//Create the message
$message =& new Swift_Message("My subject", "My body");
 
//Now check if Swift actually sends it
if ($swift->send($message, "mbent@xtalks.com", "mbent@honeycombworldwide.com")) echo "Sent";
else echo "Failed. $message";

Posted: Thu Mar 08, 2007 3:48 pm
by Chris Corbyn
You can't echo an object (unless it has a __toString()) method.

What does this show you?

Code: Select all

//Load in the files we'll need 
require_once "Swift.php"; 
require_once "Swift/Connection/SMTP.php"; 
  
//Start Swift 
$swift =& new Swift(new Swift_Connection_SMTP("mail.meaghanbent.com")); 

$swift->log->enable();

//Create the message 
$message =& new Swift_Message("My subject", "My body"); 
  
//Now check if Swift actually sends it 
if ($swift->send($message, "mbent@xtalks.com", "mbent@honeycombworldwide.com")) echo "Sent"; 
else echo "Failed. $message";

$swift->log->dump();

Posted: Thu Mar 08, 2007 4:00 pm
by $var
Failed.++ Enabling logging >> MAIL FROM: << 250 Ok >> RCPT TO: << 554 : Relay access denied !! Expected response code(s) [250] but got response [554 : Relay access denied] >> RSET << 250 Ok

Posted: Thu Mar 08, 2007 5:45 pm
by Chris Corbyn
So there you have it ;) That SMTP server is not the server you should be using. The machine your sending from has not been granted access to use that server.