Steven
Steven

Reputation: 35

PHP PEAR Mail Error

I'm getting an error with the following code when trying to send an email. It works on my local machine but not when I put it on my AWS LAMP server. I cannot debug anything because I'm getting an HTTP 500 error when I run the script. However, I know PEAR is installed.

Code:

require_once "Mail.php";

$from = "Email<[email protected]>";
$to = "[email protected]";
$subject = "ERROR REPORT";
$body = "test message";

$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "[email protected]";
$password = "pass1";

$headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);

$smtp = Mail::factory('smtp',
array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));


$mail = $smtp->send($to, $headers, $body);


if (PEAR::isError($mail)) {
    echo("<p>" . $mail->getMessage() . "</p>");
    } else {
    echo("Error message sent!");
}

It appears to be bugging out at the send() command above. Any suggestions on how to better debug this?

Upvotes: 1

Views: 10640

Answers (2)

cweiske
cweiske

Reputation: 31147

Have a look at the web server's error log, i.e. /var/log/apache2/error.log.

Upvotes: 0

Michael Petrov
Michael Petrov

Reputation: 2317

Try the following two lines:

ini_set('display_errors','on');
error_reporting(E_ALL);

Placing those two early in the script bypasses the php.ini settings that would hide the errors otherwise. Hope that helps!

Also, if you can, place them in the PHP file that gets called and then include the file that uses the mail functions. That way, you avoid the code above not working due to a syntax error.

Upvotes: 6

Related Questions