PHPMAILER不发送也不给出错误 - php

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

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   = "[email protected]"; // SMTP account username example
    $mail->Password   = "password";        // SMTP account password example

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

    $mail->AddAddress('[email protected]', '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';

参考方案

您需要致电:

$mail = new PHPMailer(true); // with true in the parenthesis

从文档中:

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

PHP:对数组排序 - php

请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…

php Singleton类实例将在多个会话中保留吗? - php

举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…