v.2.1.7 works as cron job but not 3.3.2

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
Flurrywinde
Forum Newbie
Posts: 18
Joined: Mon Feb 04, 2008 3:30 pm

v.2.1.7 works as cron job but not 3.3.2

Post by Flurrywinde »

I've been using Swift Mailer v.2.1.7 for awhile now, but also installed v. 3.3.2 (both the php4 version). Now my script no longer works when run as a cron job, though if I call it through a php file on my website using include() it works fine.

Here's the error I get:
<b>Fatal error</b>: <br /><strong>Uncaught Error</strong> of type
[swift_connectionexception] with message [Sendmail cannot be seen with
lstat(). The command given [/usr/sbin/sendmail -bs] does not appear to be
valid.]<br /> @0 swift::swift() in
/home/playb4/scripts/cron_email_beta_smtp.php on line 98<br /> @1 swift::connect() in
/home/playb4/scripts/Swift-3.3.2-php4/Swift.php on line 109<br /><br /> in
<b>/home/playb4/scripts/Swift-3.3.2-php4/Swift/Errors.php</b> on line <b>99</b><br />
Seeing that lstat() was involved, I put it lstat('/usr/sbin/sendmail'); in my script, and got:
<b>Warning</b>: lstat() [<a href='function.lstat'>function.lstat</a>]:
open_basedir restriction in effect. File(/usr/sbin/sendmail) is not
within the allowed path(s):
('.:/proc/uptime:/tmp:/home:/usr/local/lib/php:/nfs/home:/usr/home:/usr/local/bin/') in
<b>/home/playb4/scripts/cron_email_beta_smtp.php</b> on line <b>102</b><br />
It looks like v.3.3.2 uses lstat whereas v.2.1.7 didn't and was able to access /usr/sbin/sendmail with no problem. What can I do to fix this?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: v.2.1.7 works as cron job but not 3.3.2

Post by Chris Corbyn »

It's a php.ini setting. open_basedir is a sort of chroot for PHP. Are these two scenarios on the same server or different servers?

Removing that part of the code (my check for lstat()) will do harm however. I added it to lessen support from people who didn't have sendmail installed. With v2, if sendmail wasn't there, popen() would cause a hang since a bash process would start and then just sit there. This is more of a popen() bug than anything.

If you know for a fact sendmail is there, just edit that class and remove that condition.
Flurrywinde
Forum Newbie
Posts: 18
Joined: Mon Feb 04, 2008 3:30 pm

Re: v.2.1.7 works as cron job but not 3.3.2

Post by Flurrywinde »

It's the same server. Also, the v.3.3.2 code works fine if I call it from a file on my website. My cron jobs, however, I store outside of public_html. Thus, I think the server has some extra restrictions there. (I'm on a shared hosting plan.) I put a php.ini file in that directory, but it didn't help. Cool about removing the lstat() call. I'll do that if the host can't help me get around the restriction.
Terradon
Forum Newbie
Posts: 3
Joined: Sat Feb 23, 2008 9:32 am

Re: v.2.1.7 works as cron job but not 3.3.2

Post by Terradon »

Maybe the server sees it as a different owner of the files? So different rights...

I have had the same problem, my hosting provider has activated a cronjob for me which will be called every 5 minutes. But my newsletters weren't sent.....
After i created special files for maintenance activities inside public_html directory, and just included the files when needed (case select) it worked fine.

I have no knowledge of servers, but i just understood it had something to do with server / file / access rigths
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: v.2.1.7 works as cron job but not 3.3.2

Post by Chris Corbyn »

You guys will be pleased to know I approached this from a different angle in version 4 (a few weeks away). Version 4 attempts to launch sendmail without checking if it's there, but catches anything in STDERR if it fails. This seems completely bulletproof to me.

I'll be seeking beta testers (around 15-20) shortly but not just yet.
Flurrywinde
Forum Newbie
Posts: 18
Joined: Mon Feb 04, 2008 3:30 pm

Re: v.2.1.7 works as cron job but not 3.3.2

Post by Flurrywinde »

That's good, because my host couldn't fix it. I removed the lstat() call, and now everything's fine. I could have also moved the file inside my public_html directory. I guess outside of public_html, the php settings aren't user modifiable, so the open_basedir restriction can't be changed. (It's a shared hosting environment.)

Great work, by the way, Chris! Thanks for all the help too.
Post Reply