Problem sending mail with Pear in PHP
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 = "name@domain.com";
$subject = "Contact Form Submission";
$smtphost = "localhost开发者_C百科";
$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
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; }
Try changin the $smtphost = "localhost";
to your server domain url
精彩评论