Big Problem trying to run Swift.

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
geddi
Forum Commoner
Posts: 39
Joined: Sun Feb 24, 2008 11:01 am

Big Problem trying to run Swift.

Post by geddi »

Hi

I have uploaded the Swift mailer software to one of my VS (website)

It is located at http://www.fethiye-guide.com/lib

I have uploaded the php5 version and I am running php5.1

The strange thing is - it completely hangs when trying to process the file.
I don't get any errors - the server just does not do anything with the scripts.

I have written a test mailer script to use the swift library.

This is it:

Actually the first short script calls the main script. - This is to show that the first script is running OK

Code: Select all

<?php 
/*
*  test-it.php
*
*/
 
echo "This is test-it.php";
 
include_once("test-mail.php");
 
echo "This is test-it.php no. 2";
 
?> 
 
----------------------- end of first script ------------------

Code: Select all

<?php 
/* 
*       test-mail.php
*
*  
*/     
 
   echo "got here email 000 <br>";
     
$to  = "dave.fethiye@gmail.com";
$name = "Dave";
$from = "admin@fethiye-guide.com";
$from_name = "David";
 
$subjectX = "Please confirm your advert listing.";
 
   echo "got here email 00 <br>";
     
$messageX = "this is a test message";
 
   echo "got here email 01 <br>";
     
//Load in the files we'll need
require_once "/lib/Swift.php";
require_once "/lib/Swift/Connection/SMTP.php";
 
   echo "got here email 02 <br>"; 
//Start Swift
$swift = new Swift(new Swift_Connection_SMTP("localhost"));
 
    echo "got here email 03 <br>";
        
//Create the message
$message = new Swift_Message($subjectX,$messageX, "text/html");
 
   echo "got here email 04 <br>";
 
//Now check if Swift actually sends it
if ($swift->send($message, new Swift_Address($to, $name),
    new Swift_Address($from, $from_name)){
        echo "Sent to $sent recipients";
        }
else{
   echo "Failed";
     }  // end else
 
//It's polite to do this when you're finished
$swift->disconnect();
 
   echo "got here email 05 <br>";
 
?>
 
The only output from the echo's I get is :

This is test-it.php

You can try yourself at :

http://www.fethiye-guide.com/test-it.php

Any ideas on this ?

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

Re: Big Problem trying to run Swift.

Post by Chris Corbyn »

Sorry, from your PM's I thought it was hanging not dying :)

It looks like a fatal error is occurring and you don't have error reporting on.

Put this at the top of your script and run it again:

Code: Select all

<?php
 
error_reporting(E_ALL); ini_set('display_errors', true);
 
?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Big Problem trying to run Swift.

Post by Chris Corbyn »

And it's almost certainly going to be because these paths are wrong:

require_once "/lib/Swift.php";
require_once "/lib/Swift/Connection/SMTP.php";

The first slash tells it to look at the root of the server's filesystem (like looking at C:\ on windows). Use the absolute path or a relative path.
geddi
Forum Commoner
Posts: 39
Joined: Sun Feb 24, 2008 11:01 am

Re: Big Problem trying to run Swift.

Post by geddi »

OK so I was assuming that root was the public files - but I guess thats wrong.

The absolute path should be like this I guess:

http://www.fethiye-guide.com/lib/Swift.php

yes ?


Now - I just put the error stuff in and I get this:

Parse error: syntax error, unexpected '{' in /home/fethiye-guide/public_html/test-mail.php on line 39

Thats before changing the path


I'LL JUST change the path ...


changed to :

Code: Select all

/Load in the files we'll need
require_once "www.fethiye-guide.com/lib/Swift.php";
require_once "www.fethiye-guide.com/lib/Swift/Connection/SMTP.php";
 
 

I still get this:


Parse error: syntax error, unexpected '{' in /home/fethiye-guide/public_html/test-mail.php on line 39

This is from that code:

38 if ($swift->send($message, new Swift_Address($to, $name),
39 new Swift_Address($from, $from_name)){
40 echo "Sent to $sent recipients";
41 }

As I said before - I have no idea where the variable $sent comes from is it from swift itself ?

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

Re: Big Problem trying to run Swift.

Post by Chris Corbyn »

geddi wrote:OK so I was assuming that root was the public files - but I guess thats wrong.

The absolute path should be like this I guess:

http://www.fethiye-guide.com/lib/Swift.php

yes ?
I think you're getting mixed up between what you see in your browser and what's on the server. The server has a disk with a filesystem on it. That filesystem knows nothing about HTTP or about your website. PHP lives on the filesystem, so all it knows is what's on the filesystem too.

If you have scripts in folders like this:

folder/foo.php
bar.php

Then if foo.php want's to include bar.php it needs to do:

Code: Select all

require_once '../bar.php';
The ".." means relative to where I am now, go up to the parent folder.

That's a relative filesystem path. An absolute one would look more like this:

/home/username/public_html/folder/foo.php
/home/username/public_html/bar.php

The starting slash means it's starting (absolutely) at the root of the filesystem.

You can work out your absolute path to Swift based on the path shown in the error message you posted:

Code: Select all

require_once '/home/fethiye-guide/public_html/lib/Swift.php';
You'll need to know where you put Swift before you can include it ;)
Now - I just put the error stuff in and I get this:

Parse error: syntax error, unexpected '{' in /home/fethiye-guide/public_html/test-mail.php on line 39
It's parse error because you've got unpaired parentheses () in your if statement immediately before it. Using an editor which does source code highlighting and bracket matching would help you spot this... there are plenty of free editors to download and use and I strongly recommend that you do.
geddi
Forum Commoner
Posts: 39
Joined: Sun Feb 24, 2008 11:01 am

Re: Big Problem trying to run Swift.

Post by geddi »

Hello
again.

OK I have changed the code to:

require_once "/home/fethiye-guide/public_html/lib/Swift.php";
require_once "/home/fethiye-guide/public_html/lib/Swift/Connection/SMTP.php";

BUT ... I guess this should really be necassary because I put the lib in the public area it must be found by php anyway

ANYWAY - I did the change.

I use HTML-Kit for coding - but I dont think it highlights opening and closing brackets.
Still I am used to it and I dont usually get this sort of problem.

Code: Select all

//Now check if Swift actually sends it
if ($swift->send($message, new Swift_Address($to, $name),new Swift_Address($from, $from_name)))
     {
        echo "Sent to $sent recipients";
        }
else{
   echo "Failed";
     }  // end else
 
//It's polite to do this when you're finished
$swift->disconnect();
 
OK - it is working now except I get this error:

"Undefined variable: sent in /home/fethiye-guide/public_html/test-mail.php on line 41"

yep this is
41: echo "Sent to $sent recipients";

You didn't come back to me about $sent - I guess I can delete it or use my $to variable.
Is that what is supposed to display ?

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

Re: Big Problem trying to run Swift.

Post by Chris Corbyn »

Code: Select all

if ($sent = $swift->send($message, new Swift_Address($to, $name),new Swift_Address($from, $from_name)))
Post Reply