PHPMAILER未发送和未给出错误

PHPMAILER未发送和未给出错误,php,smtp,phpmailer,Php,Smtp,Phpmailer,我试图让用户填写一份联系表,然后将其发送到我的电子邮件中。但由于某些原因,它不起作用。我只是得到一个空白页没有错误信息或任何文本和电子邮件也没有发送 if (isset($_POST['submit'])) { include_once('class.phpmailer.php'); $name = strip_tags($_POST['full_name']); $email = strip_tags ($_POST['email']); $msg = str

我试图让用户填写一份联系表,然后将其发送到我的电子邮件中。但由于某些原因,它不起作用。我只是得到一个空白页没有错误信息或任何文本和电子邮件也没有发送

if (isset($_POST['submit']))
{
    include_once('class.phpmailer.php');

    $name = strip_tags($_POST['full_name']);
    $email = strip_tags ($_POST['email']);
    $msg = strip_tags ($_POST['description']);

    $subject = "Contact Form from DigitDevs Website";

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->CharSet = 'UTF-8';

    $mail->Host       = "mail.example.com"; // SMTP server example
    //$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
    $mail->Username   = "info@example.com"; // SMTP account username example
    $mail->Password   = "password";        // SMTP account password example

    $mail->From = $email;
    $mail->FromName = $name;

    $mail->AddAddress('info@example.com', 'Information'); 
    $mail->AddReplyTo($email, 'Wale');

    $mail->IsHTML(true);

    $mail->Subject = $subject;

    $mail->Body    =  $msg;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->Send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit;
}
echo 'Message has been sent';

PHPMailer使用异常

试试这个

try {

    include_once('class.phpmailer.php');

    $name = strip_tags($_POST['full_name']);
    $email = strip_tags ($_POST['email']);
    $msg = strip_tags ($_POST['description']);

    $subject = "Contact Form from DigitDevs Website";

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->CharSet = 'UTF-8';

    $mail->Host       = "mail.example.com"; // SMTP server example
    //$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
    $mail->Username   = "info@example.com"; // SMTP account username example
    $mail->Password   = "password";        // SMTP account password example

    $mail->From = $email;
    $mail->FromName = $name;

    $mail->AddAddress('info@example.com', 'Information'); 
    $mail->AddReplyTo($email, 'Wale');

    $mail->IsHTML(true);

    $mail->Subject = $subject;

    $mail->Body    =  $msg;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->Send();

    exit;

} catch (phpmailerException $e) {
  echo $e->errorMessage(); //error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage();
}

它现在可以工作了,我没有包括'class.smtp.php'文件。工作代码如下:

 if (isset($_POST['submit']))
{
 include_once('class.phpmailer.php');

 require_once('class.smtp.php');

$name = strip_tags($_POST['full_name']);
$email = strip_tags ($_POST['email']);
$msg = strip_tags ($_POST['description']);

$subject = "Contact Form from DigitDevs Website";

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';

$mail->Host       = "mail.example.com"; // SMTP server example
//$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "info@example.com"; // SMTP account username example
$mail->Password   = "password";        // SMTP account password example

$mail->From = $email;
$mail->FromName = $name;

$mail->AddAddress('info@example.com', 'Information'); 
$mail->AddReplyTo($email, 'Wale');

$mail->IsHTML(true);

$mail->Subject = $subject;

$mail->Body    =  $msg;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
 echo 'Message has been sent';

即使启用了SMTPDebug,我也有同样的问题,没有错误消息。在搜索工作示例后,我注意到我没有包含SMTP Secure值。尝试添加以下行:

$mail->SMTPSecure = 'ssl'; //secure transfer enabled

现在工作起来很有魅力。

我试图加载一个HTML文件来发送,它不属于我的Ubuntu服务器上的www数据组

chown -R www-data * 
chgrp -R www-data *

问题解决了

对我有效的是将From设置为用户名,FromName设置为$\u POST['email']

希望这有帮助

您需要拨打:

$mail = new PHPMailer(true); // with true in the parenthesis
从文件中:

true
参数意味着它将对错误抛出异常,这是我们需要的 抓住


我在争论是否应该在现有的类结构中编写自己的处理程序或crowbar PHPMailer。由于PHPMailer系统中使用的spl_autoload_register函数以及我现有的类结构的多功能性,这一过程非常简单

我只是在现有的类结构中创建了一个基本类电子邮件,如下所示

<?php

   /**
     * Provides link to PHPMailer
     *
     * @author Mike Bruce
     */
   class Email {
      public $_mailer; // Define additional class variables as required by your application
      public function __construct()
      {
         require_once "PHPMail/PHPMailerAutoload.php" ;
         $this->_mailer = new PHPMailer() ;
         $this->_mailer->isHTML(true);
         return $this;
      }
   }
?>

这是一种享受,让我不用再发明轮子了。

我也遇到过类似的问题。关于@Syclone的回答。我使用的是默认的“tls”

$mail->SMTPSecure='tls'

在我把它改成
$mail->SMTPSecure='ssl'
成功了!我的邮件服务器仅接受通过SSL的连接。

请尝试以下SSL设置:

$mail->SMTPSecure  = 'tls'; //tls or ssl
$mail->SMTPOptions = array('ssl' => array('verify_peer'       => false,
                                          'verify_peer_name'  => false,
                                          'allow_self_signed' => true));

检查服务器日志并找出问题所在。您使用的是哪个操作系统?如果
Ubuntu
邮件发送失败,则在您的web根目录中创建一个名为
dead的文件。检查后,将创建一个名为
的文件。请尝试在“退出”之后插入“};”还是在上次“echo”之后?@AmalMurali这是我在日志中得到的:[28-Jun-2013 11:57:02 UTC]PHP致命错误:require_once()[]:在/home/digitdev/public_html/class.phpmailer.PHP第1004Dreamweaver行的/home/digitdev/public_html/class.phpmailer.PHP中打开所需的“class.smtp.PHP”(include_path=”:/_/PHP:/usr/lib/PHP:/usr/local/lib/PHP:/usr/lib/红色表示语法不正确…我用php应答器“”测试了代码。它没有解析错误。只需重试一次,没有代码错误,但仍然无法工作。我的错误日志会有帮助吗?您的电子邮件未发送或未收到?如果没有错误,您的电子邮件可能没有收到。这是正确的。我也有同样的问题,在添加class.smtp.php之后,它工作得很好。同样要求
smtp.php
对我来说也是至关重要的。先生,你真是个英雄!我已经和一个虫子战斗了一段时间,但是直到现在都找不到它!
$mail->SMTPSecure  = 'tls'; //tls or ssl
$mail->SMTPOptions = array('ssl' => array('verify_peer'       => false,
                                          'verify_peer_name'  => false,
                                          'allow_self_signed' => true));