我尝试使用pear发送电子邮件。这是我的代码
<?php
require_once "/usr/share/pear/Mail.php";
require_once "/usr/share/pear/Mail/mime.php";
$to = "Info <info@mydomain.com>";
$subject = "Contact Form - mydomain.com\r\n\r\n";
$host = "smtp.zoho.com";
$username = "noreply@mydomain.com";
$password = "abc@123";
$port = "465";
//Sender Details
$sender_name = $_POST['name'];
$from = $_POST['name']." <".$_POST['email'].">";
$sender_phone = $_POST['phone'];
//Create Message
$body = $_POST['message'];
//$body = wordwrap($body, 70, "\r\n");
$body = $body . "\r\n" . "Phone: " .$sender_phone;
if($sender_name != "" && $_POST['email'] != "" && $body != "" && $sender_phone != "")
{
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'Reply-To: ' => $from);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
header("Location:contact-us.php?mcode=1");
}
}
else
{
header("Location:contact-us.php?mcode=2");
}
?>
现在这段代码在浏览器中给出了以下错误:
当我检查我的php error_log
时,我发现了这个:
[Tue Dec 17 08:46:56 2013] [notice] child pid 7416 exit signal Segmentation fault (11) [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Notice: Undefined index: name in /var/www/html/contact-us-process.php on line 14 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Stack trace: [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP 1. {main}() /var/www/html/contact-us-process.php:0 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Notice: Undefined index: name in /var/www/html/contact-us-process.php on line 15 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Stack trace: [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP 1. {main}() /var/www/html/contact-us-process.php:0 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Notice: Undefined index: email in /var/www/html/contact-us-process.php on line 15 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Stack trace: [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP 1. {main}() /var/www/html/contact-us-process.php:0 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Notice: Undefined index: phone in /var/www/html/contact-us-process.php on line 16 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Stack trace: [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP 1. {main}() /var/www/html/contact-us-process.php:0 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Notice: Undefined index: message in /var/www/html/contact-us-process.php on line 19 [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP Stack trace: [Tue Dec 17 08:47:44 2013] [error] [client 117.198.137.57] PHP 1. {main}() /var/www/html/contact-us-process.php:0 [Tue Dec 17 08:47:45 2013] [notice] child pid 6887 exit signal Segmentation fault (11) [Tue Dec 17 08:50:26 2013] [notice] child pid 7414 exit signal Segmentation fault (11) [Tue Dec 17 09:35:48 2013] [error] [client 117.198.124.73] File does not exist: /var/www/html/favicon.ico [Tue Dec 17 09:39:46 2013] [notice] child pid 8617 exit signal Segmentation fault (11)
我正在使用带有Zoho电子邮件系统的Rackspace云。
当我这样做时:
[root@mydomain /]# find -name Mail.php
./usr/share/pear/Mail.php
这就是为什么我直接将它包含在php文件中,
当我这样做的时候,
[root@mydomain /]# find -name mime.php
./usr/share/pear/Mail/mime.php
所以我使用了require_once "/usr/share/pear/Mail/mime.php"
,但是在一个例子中,我不太清楚我为什么使用这一行。
这可能是什么原因以及我如何解决它?
答案 0 :(得分:1)
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "username"; // SMTP account username example
$mail->Password = "password"; // SMTP account password example
您可以在此处找到有关PHPMailer的更多信息:https://code.google.com/a/apache-extras.org/p/phpmailer/