Page 1 of 1

PEAR Mail can't be called from within a class?

Posted: Fri Aug 01, 2008 1:41 pm
by justin.williams
Hey all, I was wondering if anybody has encountered this before. For some reason this code will run in a normal php file but when ran in a php class the webserver gives the user a "500 Internal Server Error"... even though the script gets ran (The email still gets sent even though the server displays a "500 Internal Server Error" to the user).

-The server is IIS 7.0 (not sure if that matters)
-When ran in a non-class php file there is no error.
-When I comment out the last two lines of the code in the class file there is no error.
-Both the class and non-class files I've been using for testing are in the same directory.

This doesn't make any sense to me, does it to any of you?

Code: Select all

function mymail($to, $from, $subject, $host, $port, $username, $password, $message) { 
 
  // This is the Mail.php file from PEAR. 
  include("Mail.php"); 
 
  $headers["From"]    = $from; 
  $headers["To"]      = $to; 
  $headers["Subject"] = $subject; 
 
  $body = $message; 
 
  $params["host"] = $host; 
  $params["port"] = $port; 
  $params["auth"] = true; 
  $params["username"] = $username; 
  $params["password"] = $password; 
 
  // Create the mail object using the Mail::factory method 
  $mail_object =& Mail::factory("smtp", $params); 
 
  $mail_object->send($to, $headers, $body); 
 
}