简体   繁体   中英

Unable to send email using PHP Pear

I tried to send email using pear. Here is my code

<?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");
}
?>

Now this code gives me the following error in browser:

在此处输入图片说明

When I checked my php error_log i found this:

[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)

I am using Rackspace cloud with Zoho email system.

When I did:

[root@mydomain /]# find -name Mail.php
./usr/share/pear/Mail.php

Thats why I directly included it in php file,

Also when I did,

[root@mydomain /]# find -name mime.php
./usr/share/pear/Mail/mime.php

So I used require_once "/usr/share/pear/Mail/mime.php" , However this was there in an example, I am not so sure why I used this line.

What could be the possible reason for this and how i can solve it ?

$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

You can find more about PHPMailer here: https://code.google.com/a/apache-extras.org/p/phpmailer/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM