2013-12-17 37 views
0

我试图用梨发送电子邮件。这里是我的代码无法使用PHP梨发送电子邮件

<?php 
require_once "/usr/share/pear/Mail.php"; 
require_once "/usr/share/pear/Mail/mime.php"; 

$to = "Info <[email protected]>"; 
$subject = "Contact Form - mydomain.com\r\n\r\n"; 

$host = "smtp.zoho.com"; 
$username = "[email protected]"; 
$password = "[email protected]"; 
$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"); 
} 
?> 

下面这段代码给了我在浏览器中出现以下错误:

enter image description here

当我检查我的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云。

当我做:

[[email protected] /]# find -name Mail.php 
./usr/share/pear/Mail.php 

这就是为什么我直接包含在PHP文件,

此外,当我这样做,

[[email protected] /]# find -name mime.php 
./usr/share/pear/Mail/mime.php 

所以我用require_once "/usr/share/pear/Mail/mime.php",但是这是有在一个例子中,我不太确定我为什么使用这一行。

这可能是什么原因导致我可以解决这个问题?

+0

我可以对你的表格的HTML代码看看吗? php没有从提交的表单中获得帖子值 – sas

+0

@crack页面获取数据,当我删除'require_once'/usr/share/pear/Mail.php';' 'require_once“/ usr/share/pear/Mail/mime.php“;'它echoz一切正常 –

+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/

+0

但是这样会导致FATAL错误PHP致命错误:在第26行的/var/www/html/contact-us-process.php文件中找不到'PHP'级错误' –

+1

我有请求,请尝试phpmailer它的生命保护程序库发送电子邮件 – sas

+0

好吧,让我检查它 –