I'm trying to test running cli scripts in the background (I'm not sure if it'll be useful for my current project, but I thought I'd get it working anyways)
I'm using Win XP Home (SP2), Apache 2, PHP5
This script uses my extention of PHPMailer to send an email, I don't think the problem is with that though, but here it is just in case:
<?php
// Must include the PHPMailer class file
//require_once(dirname(__FILE__).'/phpmailer/class.phpmailer.php');
class Mailer extends PHPMailer {
// Constructor
function Mailer() {
// Get global config array
global $site;
// Setup the basic stuff
$this->From = $site['mail_from'];
$this->FromName = $site['mail_name'];
$this->Host = $site['mail_host'];
// SMTP auth?
$this->SMTPAuth = $site['smtp_auth'];
// If we need to authenticate with the SMTP server
if ($this->SMTPAuth == TRUE) {
$this->Username = $site['smtp_user'];
$this->Password = $site['smtp_pass'];
}
// Using SMTP? YUP!
$this->IsSMTP();
}
// My send function
function mysend($html = true, $wrap = 50) {
// Set WordWrap
$this->WordWrap = $wrap;
// If there is no AltBody, check if its HTML mail (default: yes)
if (empty($this->AltBody)) {
$this->IsHTML($html);
}
// Try to send it!
if (!$this->send()) {
echo "Mail could not be sent!<br>";
echo "Error: " . $mail->ErrorInfo;
echo "<pre>";
print_r($this);
echo "</pre>";
}
}
// Alias for the AddAddress function from PHPMailer
function Add($email, $name = '') {
if (!empty($name)) {
$this->AddAddress($email, $name);
} else {
$this->AddAddress($email);
}
}
function mydebug() {
echo "<pre>";
print_r($this);
echo "</pre>";
}
}
?>
I tried to keep this script fairly simple, there are two files I'm using (fork.php and mail.php), I'm not sure where the problem is so I'l post both of them
Here is fork.php:
<?php
require_once('setup.php');
function fork($file) {
exec("$site[cli_path] $_SERVER[DOCUMENT_ROOT]/$file $_SERVER[REMOTE_ADDR]");
}
fork('mail.php');
header('Location: index.php');
?>
And here is mail.php:
<?php
require_once('setup.php');
$ip = $_SERVER['argv'][0];
$mail->Subject = 'Test!';
$mail->Body = <<<_MAIL
This is a test email...<br>
I <em>really</em> hope this works :)<br>
IP: $ip
_MAIL;
$mail->Add('removed to protect from spam');
$mail->mysend();
?>
Finally, here is the $site['cli_path'] variable
<?php
$site['cli_path'] = '\\PHP\\php-win.exe';
?>
If anyone has any ideas please let me know! Thanks!