Smoke Tests fail for Sendmail & SMTP

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
marcusv
Forum Newbie
Posts: 7
Joined: Thu Jul 05, 2007 3:51 pm

Smoke Tests fail for Sendmail & SMTP

Post by marcusv »

Having some issues getting Swift working on my server. I'm use GoDaddy's Deluxe Hosting - Linux with Swift 3.2.6

I can run all the Unit Tests successfully without any errors or exceptions. However, running the Smoke Tests with Sendmail gives me a blank page in IE and asks me to save the page in Firefox after about a minute of processing.

If I use SMTP for smoke tests, it gives me the following error when using both your default settings and through Gmail.

Code: Select all

Fatal error:
Uncaught Error of type [swift_connection_exception] with message [The SMTP connection is not alive and cannot be read from. (fsockopen: #) ]
@0 testofbasicsend::go() in /home/content/html/Swift/tests/smokes/runTestOfBasicSend.php on line 55
@1 swift::swift() in /home/content/html/Swift/tests/smokes/runTestOfBasicSend.php on line 13
@2 swift::connect() in /home/content/html/Swift/lib/Swift.php on line 111

in /home/content/html/Swift/lib/Swift/Errors.php on line 99
Nativemail setting runs just fine for smoke tests.

I'd prefer to be running sendmail, but I thought I'd try all options. Thanks for any help you can give!
marcusv
Forum Newbie
Posts: 7
Joined: Thu Jul 05, 2007 3:51 pm

Post by marcusv »

It seems to be something related to fsockopen, even though GoDaddy specifically states
It doesn't seem to be connection to anything. I've submitted a support request to them and we'll see what they figure. I'm assuming this is the cause of the SMTP issue, but does sendmail use fsockopen as well? Since I can't get an error message using sendmail, I'm stumped and hoping for a little extra guidance. Please?
Sorayna
Spammer :|
Posts: 7
Joined: Wed Aug 15, 2007 8:10 am

Post by Sorayna »

:)
marcusv
Forum Newbie
Posts: 7
Joined: Thu Jul 05, 2007 3:51 pm

Post by marcusv »

So, GoDaddy has informed me that they only allow fsockopen connections on port 80 only. So that pretty much kills all hope of using the SMTP Connection, so I am now wondering whats blocking the sendmail from working - any clues? I have sendmail installed and I have the location entered correctly.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

marcusv wrote:So, GoDaddy has informed me that they only allow fsockopen connections on port 80 only. So that pretty much kills all hope of using the SMTP Connection, so I am now wondering whats blocking the sendmail from working - any clues? I have sendmail installed and I have the location entered correctly.
Sendmail usually doesn't work if your host have you inside a chroot environment where PHP cannot see it, or otherwise it's because Swift cann't "stat" it. Downloading the new version 3.3.0 and running with the highest evel of logging should provide some excellent insight into the issue:

Code: Select all

<?php

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

$log =& Swift_ClassLoader::getLog();
$log->setLogLevel(SWIFT_LOG_EVERYTHING); //level 4

$swift =& new Swift( ... );

//blah blah blah

echo "<pre>" . $log->dump(true) . "</pre>";
The "hang" issue has been a problem with GoDaddy with other people too. I think they've got some weird permissions set up.
marcusv
Forum Newbie
Posts: 7
Joined: Thu Jul 05, 2007 3:51 pm

Post by marcusv »

Thanks for the tip, however the logging doesn't help as it still times out before it can display the log.

Here is the code I used with Swift 3.3.0 (Running PHP 4.3.11)

Code: Select all

<?php
require_once "Swift/lib/Swift.php";
require_once "Swift/lib/Swift/Connection/Sendmail.php";

$log =& Swift_LogContainer::getLog();
$log->setLogLevel(SWIFT_LOG_EVERYTHING); //level 4
 
$swift =& new Swift(new Swift_Connection_Sendmail("/usr/sbin/sendmail -bs"));

$message =& new Swift_Message("My subject", "My body");
$swift->send($message, "sendemail@gmail.com", "myemail@gmail.com");

echo "<pre>" . $log->dump(true) . "</pre>"; 
?>
This is what happens -> SwiftTest

However, if I change the connection line to the following:

Code: Select all

$swift =& new Swift(new Swift_Connection_Sendmail("/usr/sbin/sendmail -t -i"));
I get this message displayed:

Code: Select all

Fatal error:
Uncaught Error of type [swift_connectionexception] with message [Sendmail cannot be seen with lstat(). The command given [/usr/sbin/sendmail -t -i] does not appear to be valid.
Log Information

++ Log level changed to 4
++ Trying to connect...
++ Trying to start a sendmail process.
++ Trying to stat the executable '/usr/sbin/sendmail -t'.

]
@0 swift::swift() in /home/content/s/h/i/shiftthis/html/22/swifttest2.php on line 8
@1 swift::connect() in /home/content/s/h/i/shiftthis/html/22/Swift/lib/Swift.php on line 109

in /home/content/s/h/i/shiftthis/html/22/Swift/lib/Swift/Errors.php on line 99
So is the -bs flag the problem? Is it perhaps disabled on GoDaddy? Or is there something I can do to make it work?

Thanks for your help, if we can get this working I will definitely make another contribution to your Oz pot!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What does this code do?

Code: Select all

$pipes_spec = array(
  array("pipe", "r"),
  array("pipe", "w"),
  array("pipe", "w")
);

$proc = proc_open("/usr/sbin/sendmail -bs", $pipes_spec, $pipes);

echo "I got here";
var_dump($proc);

proc_close($proc);
I suspect the script is running but PHP is hanging when it shuts down because it's losing scope of the resource. But if the above code hangs then GoDaddy have problems with their server permissions ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Suspicions confirmed as per your edit (gives me enough information). The "sendmail cannot be seen with lstat()" error is a permissions problem on the server. You'd have to ask GoDaddy why you can't lstat() the sendmail executable.

Add a call to disconnect() and see what happens.

Code: Select all

<?php 
require_once "Swift/lib/Swift.php"; 
require_once "Swift/lib/Swift/Connection/Sendmail.php"; 

$log =& Swift_LogContainer::getLog(); 
$log->setLogLevel(SWIFT_LOG_EVERYTHING); //level 4 
  
$swift =& new Swift(new Swift_Connection_Sendmail("/usr/sbin/sendmail -bs")); 

$message =& new Swift_Message("My subject", "My body"); 
$swift->send($message, "sendemail@gmail.com", "myemail@gmail.com"); 

echo "<pre>" . $log->dump(true) . "</pre>"; 

$swift->disconnect();
EDIT | As for the lstat() issue you can get around it if you're 100% sure the executable is there.

In Sendmail.php, lines 316-320 (roughly), remove or comment out this block.

Code: Select all

if (!@lstat($this->getPath()))
    {
      Swift_Errors::trigger(new Swift_ConnectionException(
        "Sendmail cannot be seen with lstat().  The command given [" . $this->getCommand() . "] does not appear to be valid."));
      return;
    }
The reason "-t" didn't hang is because the process doesn't stay open, whereas "-bs" opens an SMTP process and the PHP script will not end until that process ends. I use register_shutdown_function() to close it down implictly but clearly it's losing scope in your case. Closing explictly would solve that. "-t" is very different, don't use it.

I'm going to modify the sendmail connection to add a "NO_VERIFY" option which skips the checks for the binary.
marcusv
Forum Newbie
Posts: 7
Joined: Thu Jul 05, 2007 3:51 pm

Post by marcusv »

Here is the pipes script just in case -> Pipestest

It returns the following:

Code: Select all

I got hereresource(4) of type (process)
I added the call to disconnect() and it didn't have any effect on either.

I've submitted a support request to GoDaddy regarding the lstat() permissions issue. Hopefully they come up with something useful.

-EDIT-

I modified Sendmail.php as you suggested, but it doesn't seem to have any effect. I'm only as sure as what GoDaddy tells me and it is listed in my phpinfo() as well.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

marcusv wrote:I modified Sendmail.php as you suggested, but it doesn't seem to have any effect. I'm only as sure as what GoDaddy tells me and it is listed in my phpinfo() as well.
Did you also add a call to disconnect() ?
marcusv
Forum Newbie
Posts: 7
Joined: Thu Jul 05, 2007 3:51 pm

Post by marcusv »

Yes, the disconnect call is there.
marcusv
Forum Newbie
Posts: 7
Joined: Thu Jul 05, 2007 3:51 pm

Post by marcusv »

Okay, here is GoDaddy's reply:
Unfortunately you are unable to use commands on shared hosting. Please make sure you are using the correct mail relay for your mail form script. The relay should be relay-hosting.secureserver.net.
So unless you have another idea, that knocks out the sendmail option. However, after checking out a few other threads here, I came across one where you recommended trying smtp with localhost as the server. I did this and it seems to work perfectly, so I guess I'll be using that setting.

Just curious, would there be much of a speed difference between the Sendmail and SMTP using localhost?

Thanks for all your help, I'll be contributing a little donation to your Oz fund as thanks!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

The difference between using SMTP/localhost and running sendmail is six and two threes really. Swift runs sendmail in SMTP-mode anyway so you're basically doing the same thing via a different interface.

Sorry I couldn't offer much more advice on the sendmail issue but it looks like GoDaddy have given you the answer ;) I was aware that GoDaddy have very tight permissions on their shared hosting plans since others have experienced issues establishing socket connections too. Quite what the value of only allow fsockopen() connections to port 80 is I'll never know.

Thanks for the generous offer of a donation too; it's very kind of you. Getting close now!

Good luck :)
hubbers
Forum Newbie
Posts: 1
Joined: Tue Oct 21, 2008 5:33 am

Re: Smoke Tests fail for Sendmail & SMTP

Post by hubbers »

However, after checking out a few other threads here, I came across one where you recommended trying smtp with localhost as the server. I did this and it seems to work perfectly, so I guess I'll be using that setting.
Can someone provide a link to this thread with the solution?

Thanks :)
Post Reply