开发者

Problem sending mail with Pear in PHP

开发者 https://www.devze.com 2022-12-19 09:07 出处:网络
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:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号