簡體   English   中英

無法使用PHP Pear發送電子郵件

[英]Unable to send email using PHP 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)

我正在將Rackspace雲與Zoho電子郵件系統一起使用。

當我這樣做時:

[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" ,但是在示例中,我不確定為什么要使用此行。

這可能是什么原因,我該如何解決?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM