Page 1 of 2
moving host causes errors
Posted: Thu Aug 02, 2007 9:05 am
by roscoe
I have moved hosts and running the software throws up these errors:
Warning: popen() has been disabled for security reasons in /home/acappoin/public_html/mailoutattach/mylib/Swift/Connection/Sendmail.php on line 293
Warning: fread(): supplied argument is not a valid stream resource in /home/acappoin/public_html/mailoutattach/mylib/Swift/Connection/Sendmail.php on line 294
Warning: fclose(): supplied argument is not a valid stream resource in /home/acappoin/public_html/mailoutattach/mylib/Swift/Connection/Sendmail.php on line 295
Warning: proc_open() has been disabled for security reasons in /home/acappoin/public_html/mailoutattach/mylib/Swift/Connection/Sendmail.php on line 311
Fatal error:
Uncaught Error of type [Swift_Connection_Exception] with message [The sendmail process failed to start. Please verify that the path exists and PHP has permission to execute it.]
@0 Swift::Swift() in /home/acappoin/public_html/mailoutattach/mail_handler.php on line 64
@1 Swift::connect() in /home/acappoin/public_html/mailoutattach/mylib/Swift.php on line 109
in /home/acappoin/public_html/mailoutattach/mylib/Swift/Errors.php on line 99
Any ideas?
sendmail path is /usr/sbin/sendmail so it should be OK
Posted: Thu Aug 02, 2007 9:30 am
by Chris Corbyn
The error wrote:Warning: popen() has been disabled for security reasons
Your host have disabled a function which is critical for the sendmail connection to work. Try another connection although your host are more than likely going to make it very difficult to do anything on your server (I guess they'll have everything firewalled off too). If the other connections don't work your only option is to complain to your host or leave them.
The NativeMail connection should work almost all the time but I'm gonna take a stab in the dark and say you'll get "mail() has been disabled for security reasons" when you try using it.
Who are your host by the way? I like to keep track of hosts and potential problems since it helps me to troubleshoot other bugs later

Posted: Thu Aug 02, 2007 9:50 am
by roscoe
Hosts are webhosting.uk.com and I have just moved to them for greater flexibility. They offer mail lists and are happier about sending mail. They even publish the sendmail path.
I notice they are running php 5.2.0, would this have a difference, I think I had the package for 4.3?
Posted: Thu Aug 02, 2007 11:53 am
by Chris Corbyn
roscoe wrote:Hosts are webhosting.uk.com and I have just moved to them for greater flexibility. They offer mail lists and are happier about sending mail. They even publish the sendmail path.
I notice they are running php 5.2.0, would this have a difference, I think I had the package for 4.3?
It's not a problem with Swift. The host have physcially disabled the use of a standard PHP function. The PHP version makes no difference, although you'll be better off upgrading to the PHP5 version of Swift if they enable the popen() function for you

popen() - any options other than use this?
Posted: Thu Aug 02, 2007 11:54 am
by roscoe
popen() cannot be used, any options or work arounds ? Please, pretty please????

Re: popen() - any options other than use this?
Posted: Thu Aug 02, 2007 12:03 pm
by Chris Corbyn
roscoe wrote:popen() cannot be used, any options or work arounds ? Please, pretty please????

popen() is the only function of that nature I'm afraid.
Posted: Thu Aug 02, 2007 12:07 pm
by roscoe
Does the SMTP use it too?
Posted: Thu Aug 02, 2007 12:21 pm
by Chris Corbyn
roscoe wrote:Does the SMTP use it too?
No SMTP uses fsockopen() so that may work

Posted: Thu Aug 02, 2007 12:35 pm
by roscoe
OK any chance you can point me in the right direction here, I been working for 14 hours straight
When I tried smtp before it bombed. I will need authentication too.
Code: Select all
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["sender_name"]) || empty($_POST["sender_email"])
|| empty($_POST["comment_title"]) || empty($_POST["comment_body"]))
{
//redirect back to form
header("Location: form.php?error=not_enough_info"); //This should really be an absolute URL if you know it
exit();
}
//Copy into global variables
$name = $_POST["sender_name"];
$email = $_POST["sender_email"];
$title = $_POST["comment_title"];
$body = $_POST["comment_body"];
$sendout = $_POST["to"];
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9_\\.-]+/", $email))
{
header("Location: form.php?error=invalid_email");
exit();
}
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: ./form.php?error=upload_failed");
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Everything looks ok, we can start Swift
require_once "mylib/Swift.php";
require_once "mylib/Swift/Connection/Sendmail.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
//Create a Swift instance
//$swift =& new Swift(new Swift_Connection_SMTP("mail.fred.com"));
//Try to connect using /usr/sbin/sendmail -bs
$sendmail =& new Swift_Connection_Sendmail();
$sendmail->setTimeout(3); //3 seconds
$swift =& new Swift($sendmail);
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
//Create the message to send
$message =& new Swift_Message("New comment: " . $title);
$message->attach(new Swift_Message_Part($body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
//Try sending the email
$sent = $swift->send($message, $sendout, $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: success.php");
exit();
}
else
{ echo"sending_failed";
exit;
header("Location: form.php?error=sending_failed");
exit();
}
Posted: Thu Aug 02, 2007 12:52 pm
by Chris Corbyn
Can you show me what you tried with SMTP?
Posted: Thu Aug 02, 2007 1:02 pm
by roscoe
Sorry, I think you can see where I have // out the smtp bits. This was where we started.
My brain is kind of addled after moving 40 websites this week.
I have not got the original script, my system went FUBAR and this script was working on the old server for sendmail. It is all I have left

Posted: Thu Aug 02, 2007 1:07 pm
by Chris Corbyn
Ah ok, yes I see now

You're creating $swift but then your overwriting it afterwards. Remove the second "$swift =& ..." or change the first one to just create an instance of Swift_Connection_SMTP() then pass that to $swift later like we were doing with the sendmail version. Using Swift with SMTP or sendmail is exactly the same except you use a different class name that's all

Posted: Thu Aug 02, 2007 1:18 pm
by roscoe
Ok I have had the first bash
Code: Select all
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["sender_name"]) || empty($_POST["sender_email"])
|| empty($_POST["comment_title"]) || empty($_POST["comment_body"]))
{
//redirect back to form
header("Location: form.php?error=not_enough_info"); //This should really be an absolute URL if you know it
exit();
}
//Copy into global variables
$name = $_POST["sender_name"];
$email = $_POST["sender_email"];
$title = $_POST["comment_title"];
$body = $_POST["comment_body"];
$sendout = $_POST["to"];
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9_\\.-]+/", $email))
{
header("Location: form.php?error=invalid_email");
exit();
}
//Check if an attachment was uploaded
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["attachment"]["tmp_name"]))
{
if ($_FILES["attachment"]["error"])
{
//Redirect if the upload has failed
header("Location: ./form.php?error=upload_failed");
exit();
}
$file_path = $_FILES["attachment"]["tmp_name"];
$file_name = $_FILES["attachment"]["name"];
$file_type = $_FILES["attachment"]["type"];
}
//Everything looks ok, we can start Swift
require_once "mylib/Swift.php";
require_once "mylib/Swift/Connection/SMTP.php";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Create a Swift instance
//$swift =& new Swift(new Swift_Connection_SMTP("your_smtp_server.tld"));
//Try to connect using /usr/sbin/sendmail -bs
//$sendmail =& new Swift_Connection_Sendmail();
//$sendmail->setTimeout(3); //3 seconds
$swift =& new Swift($SMTP);
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
//Create the message to send
$message =& new Swift_Message("New comment: " . $title);
$message->attach(new Swift_Message_Part($body));
//If an attachment was sent, attach it
if ($file_path && $file_name && $file_type)
{
$message->attach(
new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
}
//Try sending the email
$sent = $swift->send($message, $sendout, $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
header("Location: success.php");
exit();
}
else
{ echo"sending_failed";
exit;
header("Location: form.php?error=sending_failed");
exit();
}
error message:
Notice: Swift requires constructor parameter 1 to be instance of Swift_Connection. in /home/acappoin/public_html/mailoutattach/mylib/Swift.php on line 91
Fatal error: Call to a member function isEnabled() on a non-object in /home/acappoin/public_html/mailoutattach/mylib/Swift.php on line 404
???
Posted: Thu Aug 02, 2007 1:25 pm
by Chris Corbyn
You're still creating $swift twice, and where did $SMTP appear from?
Quite literally, just do it like you did it for sendmail.
Code: Select all
$smtp =& new Swift_Connection_SMTP("localhost");
//Create a Swift instance
//$swift =& new Swift(new Swift_Connection_SMTP("your_smtp_server.tld"));
//Try to connect using /usr/sbin/sendmail -bs
//$sendmail =& new Swift_Connection_Sendmail();
//$sendmail->setTimeout(3); //3 seconds
$swift =& new Swift($smtp);
Posted: Thu Aug 02, 2007 1:25 pm
by roscoe
removed the
and now it says
sending_failed.
No authentication is required, I have checked that.
Where to from here?