views:

53

answers:

2

I have written an email contact form in php. I am using the Pear Mail package to send the email. It works nicely on my development computer, but not on the server. Here is the code:

//////////////////////////////////////////////////
// EMAIL OPTIONS
//////////////////////////////////////////////////
$to = "[email protected]";              
$subject = "Contact Form Submission";           
$smtphost = "localhost";
$port = "25";
$authenticate = false;
$username = "smtp_username";
$password = "smtp_password";

// create and send the email
$from = $_POST['fullname'] . " <" . $_POST['email'] . ">";
$body = str_replace($ph, $rv, $emailTemplate);

$headers = array (
    'MIME-Version' => '1.0',
    'Content-type' => 'text/html; charset=iso-8859-1',
    'From' => $from,
    'To' => $to,
    'Subject' => $subject);

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

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

$error = PEAR::isError($mail);

if ($error){
    echo 'An error occurred.';
}
else {
    require('thanks.php');
    exit;
}

I don't know why it's failing on the server. How can I get some more useful information out of my $error object?

Echoing $error results with

1
A: 

Try changin the $smtphost = "localhost"; to your server domain url

streetparade
That doesn't answer my question about getting more useful info from the $error object. I'm not worried about my smtp server host being wrong.
Ronnie Overby
Please Post the Output of $error
streetparade
If I just echo $error all I get is 1.
Ronnie Overby
+2  A: 

Have a look at http://pear.php.net/manual/en/core.pear.pear-error.php and do something like:

if ($error){
    echo 'An error occurred.';
    echo $error->getMessage(), "\n";
}
else {
    require('thanks.php');
    exit;
}
kguest