[SOLVED] Trying to get SwiftMailer Working...

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
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

[SOLVED] Trying to get SwiftMailer Working...

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

looks like you are trying to use the php5 version of swiftmailer. download the version for php4
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post 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! :)
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

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

Post 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();
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

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

Post 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.
Post Reply