我在php写了一封电子邮件联系表格。我正在使用Pear Mail包发送电子邮件。它在我的开发计算机上运行良好,但在服务器上运行不正常。这是代码:
//////////////////////////////////////////////////
// EMAIL OPTIONS
//////////////////////////////////////////////////
$to = "name@domain.com";
$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;
}
我不知道为什么它在服务器上失败了。如何从$ error对象中获取更多有用的信息?
使用
回应$ error结果1
答案 0 :(得分:2)
查看http://pear.php.net/manual/en/core.pear.pear-error.php并执行以下操作:
if ($error){ echo 'An error occurred.'; echo $error->getMessage(), "\n"; } else { require('thanks.php'); exit; }
答案 1 :(得分:0)
尝试更改$smtphost = "localhost";
到您的服务器域URL