I am having a very similar problem posed by this question, unfortunately the answers in that thread have not helped me.
Nothing seems to run after the $mail = Mail::factory('smtp', $params);
.
None of the echo statements or the error checks after output anything, its as though when the script reaches the Mail::factory
line the script just stops.
The script itself returns a HTTP 200, though the mail is not sent or any sent/not sent responses the script generates is returned.
I have tried uninstalling/re-installing the PEAR Mail, Net and Auth libraries and the problem still persists.
I also tried running the script on the server directly from the command line,
It's as though once the Mail::factory
called is made the script stops processing anymore, no errors are returned so I have no clue where to start looking to get this fixed.
I have also run the script directly on the server through the PHP CLI:
It outputs everything until the Mail::factory
call and nothing after.
D:\Parallels\Additional\PleskPHP5>php phpmailcheck.php
PEAR is installed!
PEAR Mail is installed!
going to call Mail::factory
D:\Parallels\Additional\PleskPHP5>
I have also checked the sites error logs and there are no errors reported.
UPDATE:
I have tried adding the following just before the Mail::factory
call: echo(Mail::factory('smtp', $params));
which from the pear mail documentation says it should return an object or an error message.
the script seems to end on this line without echoing anything...
<?php
require_once('D:\Parallels\Additional\PleskPHP5\Pear\System.php');
require_once "Mail.php";
if(class_exists('System')===true) {
echo '<p>PEAR is installed!</p>';
} else {
echo '<p>PEAR is not installed!</p>';
}
if(class_exists('Mail')===true) {
echo '<p>PEAR Mail is installed!</p>';
} else {
echo '<p>PEAR Mail is not installed!</p>';
}
//start mail
$from = "My Website <[email protected]>";
$to = "Website Owner <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?<br>This is a test email for pear";
$host = "mail.mailserver.co.uk";
$port = 25;
$username = "[email protected]";
$password = "password";
$params = array('host'=>$host,'port'=>$port,'auth'=>true,'username'=>$username,'password'=>$password);
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject
);
echo('going to call Mail::factory'); //echos out correctly
$mail = Mail::factory('smtp', $params);
echo('just called Mail::factory'); // does not echo
$mail->send($to,$headers,$message);
//$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
First, check the exit status:
$ php mailcheck.php; echo $?
or on windows:
$ php mailcheck.php
$ echo Exit Code is %errorlevel%
It will be > 0 if there was a fatal error within the php code.
Then make sure you have display_errors
on and error_reporting
set to the correct level. If you don't, you won't see any output. If you have xdebug installed, enable xdebug.scream
.
Since you have exit code 255, there is something broken with your php files.
First, use ini_set
to set display_errors to 1 and error_reporting to E_ALL. Run the code again.
If that does not hepl make sure the code is syntactically correct by running
$ php -l path/to/file.php
It will tell you when there is a syntax error. Do this for all files.