smtp php电子邮件脚本不发送电子邮件

时间:2015-01-12 20:29:53

标签: php email smtp gmail

由于某种原因,根本没有发送电子邮件。我没有得到任何控制台错误,输入字段甚至像他们应该的那样重置。它正在Windows服务器上处理,因此需要gmail smtp。有什么想法吗?

<?php

require 'PHPMailerAutoload.php';
require_once('class.phpmailer.php');
include("class.smtp.php");

$emailaddress = 'levyandrew44@gmail.com';
$message=
'Name:  '.$_POST['name'].'<br />
Email:  '.$_POST['email'].'<br />
Phone:  '.$_POST['phone'].'<br />
Comments:   '.$_POST['comments'].'<br />
'.nl2br($_POST['message']).'
';

$mail             = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->SMTPDebug  = 2;                     // 1 = errors and messages,2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.gmail.com"; // sets the SMTP server
$mail->Port       = 465;                    // set the SMTP port for the GMAIL server
$mail->Username   = "info@newpointdigital.com"; // SMTP account username (the email account your created)
$mail->Password   = "newpoint!@#$";        // SMTP account password (the password for the above email account)
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
$mail->CharSet  = 'UTF-8';  // so it interprets foreign characters
$mail->SetFrom($_POST['email']);
$mail->AddReplyTo($_POST['email']);
$mail->Subject    = "Contact form from ".$_POST['name']." ";
$mail->MsgHTML($message);
$mail->AddAddress($emailaddress);                    
if(isset($_POST['submit'])) {
    if(!$mail->send()) {
        echo '<p class="contact-message">Message could not be sent.</p>';
        echo '<p class="contact-message">Mailer Error: ' . $mail->ErrorInfo . '</p>';
    } else {
        echo '<p class="contact-message">Your message has been sent. We will be in touch.';
    }       
}
?>
  <form role="form" method="post" id="contact-form" name="myemailform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>#contact-form">

   <div class="row">
    <div class="col-sm-12 col-md-12 col-lg-12 "><input type="text" class="form-control" name="name" placeholder="Name*"></div>

   <div class="col-sm-12 col-md-12 col-lg-12"><input type="text" class="form-control" name="email" placeholder="E-mail*"></div>

   <div class="col-sm-12 col-md-12 col-lg-12"><input type="text" class="form-control" name="phone" placeholder="Telephone Number"></div>

   <div class="col-sm-12 col-md-12 col-lg-12"><textarea name="comments" class="form-control commentBox" placeholder="Comments"></textarea></div>

   <div class="col-sm-12 col-md-12 col-lg-12"><input type="submit" value="Send Form" class="form-control submitButton"></div>
       </div>
  </form>

来自MAMP PHP_ERROR.LOG的错误

[12-Jan-2015 17:27:06 America/New_York] PHP Notice:  Undefined index: name in /Users/andrewlevy/Documents/deepseadiving/index.php on line 22
[12-Jan-2015 17:27:06 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 23
[12-Jan-2015 17:27:06 America/New_York] PHP Notice:  Undefined index: phone in /Users/andrewlevy/Documents/deepseadiving/index.php on line 24
[12-Jan-2015 17:27:06 America/New_York] PHP Notice:  Undefined index: comments in /Users/andrewlevy/Documents/deepseadiving/index.php on line 25
[12-Jan-2015 17:27:06 America/New_York] PHP Notice:  Undefined index: message in /Users/andrewlevy/Documents/deepseadiving/index.php on line 26
[12-Jan-2015 17:27:06 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 39
[12-Jan-2015 17:27:06 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 40
[12-Jan-2015 17:27:06 America/New_York] PHP Notice:  Undefined index: name in /Users/andrewlevy/Documents/deepseadiving/index.php on line 41
[12-Jan-2015 17:28:15 America/New_York] PHP Notice:  Undefined index: name in /Users/andrewlevy/Documents/deepseadiving/index.php on line 22
[12-Jan-2015 17:28:15 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 23
[12-Jan-2015 17:28:15 America/New_York] PHP Notice:  Undefined index: phone in /Users/andrewlevy/Documents/deepseadiving/index.php on line 24
[12-Jan-2015 17:28:15 America/New_York] PHP Notice:  Undefined index: comments in /Users/andrewlevy/Documents/deepseadiving/index.php on line 25
[12-Jan-2015 17:28:15 America/New_York] PHP Notice:  Undefined index: message in /Users/andrewlevy/Documents/deepseadiving/index.php on line 26
[12-Jan-2015 17:28:15 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 39
[12-Jan-2015 17:28:15 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 40
[12-Jan-2015 17:28:15 America/New_York] PHP Notice:  Undefined index: name in /Users/andrewlevy/Documents/deepseadiving/index.php on line 41
[12-Jan-2015 17:28:17 America/New_York] PHP Notice:  Undefined index: name in /Users/andrewlevy/Documents/deepseadiving/index.php on line 22
[12-Jan-2015 17:28:17 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 23
[12-Jan-2015 17:28:17 America/New_York] PHP Notice:  Undefined index: phone in /Users/andrewlevy/Documents/deepseadiving/index.php on line 24
[12-Jan-2015 17:28:17 America/New_York] PHP Notice:  Undefined index: comments in /Users/andrewlevy/Documents/deepseadiving/index.php on line 25
[12-Jan-2015 17:28:17 America/New_York] PHP Notice:  Undefined index: message in /Users/andrewlevy/Documents/deepseadiving/index.php on line 26
[12-Jan-2015 17:28:17 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 39
[12-Jan-2015 17:28:17 America/New_York] PHP Notice:  Undefined index: email in /Users/andrewlevy/Documents/deepseadiving/index.php on line 40
[12-Jan-2015 17:28:17 America/New_York] PHP Notice:  Undefined index: name in /Users/andrewlevy/Documents/deepseadiving/index.php on line 41
[12-Jan-2015 17:28:56 America/New_York] PHP Notice:  Undefined index: message in /Users/andrewlevy/Documents/deepseadiving/index.php on line 26
[12-Jan-2015 17:29:04 America/New_York] PHP Notice:  Undefined index: message in /Users/andrewlevy/Documents/deepseadiving/index.php on line 26

2 个答案:

答案 0 :(得分:0)

将class.smtp.php gmail SMTP类包含到自动加载器文件中。如果您自己的smtp类是标准的PHPMailer,那么只需删除该include并让自动加载器对其进行排序。

在页面顶部也可以执行以下操作:

error_reporting(E_ALL);
ini_set('display errors',1);

应该给你PHP警告,而不仅仅是致命的错误。

答案 1 :(得分:0)

PHP错误报告:

我有一种印象 - 速读原始问题 - 你没有错误,但通过评论的对话,我现在看到你没有看到任何错误,但那不是因为没有错误,而是因为你正在寻找因为他们在错误的地方。

在PHP中查找错误:

在页面的最顶部添加以下行:

///set log errors to TRUE
    ini_set("log_errors", 1);
/// show all ERRORS, WARNINGS and NOTICES
    error_reporting(E_ALL);
///set where these errors are recorded.
    ini_set("error_log", "/ *whateveryourwebfolderis* /php-errors.log");

现在运行你的脚本和(S)FTP到你的服务器空间并找到你拥有的web文件夹,其中应该是一个名为“php-errors.log”的文件,下载并用代码程序打开它或者一个记事本,它将从PHP中输出奇怪的错误。

并告诉我们您从此文件中获得的反馈。