PHP PEAR Mail Error

10,134

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.

Share:
10,134
Steven
Author by

Steven

Updated on November 20, 2022

Comments

  • Steven
    Steven over 1 year

    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?

  • Steven
    Steven almost 13 years
    Thank you! This worked. Problem was I didn't have Net_SMTP installed