For some reason emails are not being sent at all. Im not getting any console errors, the input fields even reset like they are supposed to. It is being processed on a Windows server, thus the need for the gmail smtp. Any thoughts?
由于某种原因,根本没有发送电子邮件。我没有得到任何控制台错误,输入字段甚至像他们应该的那样重置。它正在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>
ERRORS FROM MAMP PHP_ERROR.LOG
来自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 个解决方案
#1
0
include your class.smtp.php gmail SMTP class into the autoloader file. If your own smtp class is the standard PHPMailer one then just remove that include and let the autoloader sort it.
将class.smtp.php gmail SMTP类包含到自动加载器文件中。如果您自己的smtp类是标准的PHPMailer,那么只需删除该include并让自动加载器对其进行排序。
Also useful at the top of the page to do something like:
也可以在页面顶部执行以下操作:
error_reporting(E_ALL);
ini_set('display errors',1);
which should give you PHP Warnings, rather than just fatal errors.
哪个应该给你PHP警告,而不仅仅是致命的错误。
#2
0
PHP Error reporting:
PHP错误报告:
I was under an impression - speed reading your original Question - that you had no errors, but with conversation of comments I now see you saw no errors, but that was not because there are no errors, but because you're looking for them in the wrong place.
我的印象很快 - 阅读你的原始问题的速度 - 你没有错误,但通过评论的对话,我现在看到你没有看到任何错误,但这不是因为没有错误,而是因为你正在寻找他们错误的地方。
To find errors in PHP:
要在PHP中查找错误:
at the very top of the page add these lines:
在页面的最顶部添加以下行:
///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");
Now run your script, and (S)FTP to your server space and find the web folder you have and in it should be a file called "php-errors.log", download it and open it with a code program or a notepad, and it will output verious errors from PHP.
现在运行你的脚本,然后(S)FTP到你的服务器空间,找到你拥有的web文件夹,里面应该是一个名为“php-errors.log”的文件,下载并用代码程序或记事本打开它,它将从PHP输出错误的错误。
And give us the feedback you get from this file.
并向我们提供您从此文件中获得的反馈。
#1
0
include your class.smtp.php gmail SMTP class into the autoloader file. If your own smtp class is the standard PHPMailer one then just remove that include and let the autoloader sort it.
将class.smtp.php gmail SMTP类包含到自动加载器文件中。如果您自己的smtp类是标准的PHPMailer,那么只需删除该include并让自动加载器对其进行排序。
Also useful at the top of the page to do something like:
也可以在页面顶部执行以下操作:
error_reporting(E_ALL);
ini_set('display errors',1);
which should give you PHP Warnings, rather than just fatal errors.
哪个应该给你PHP警告,而不仅仅是致命的错误。
#2
0
PHP Error reporting:
PHP错误报告:
I was under an impression - speed reading your original Question - that you had no errors, but with conversation of comments I now see you saw no errors, but that was not because there are no errors, but because you're looking for them in the wrong place.
我的印象很快 - 阅读你的原始问题的速度 - 你没有错误,但通过评论的对话,我现在看到你没有看到任何错误,但这不是因为没有错误,而是因为你正在寻找他们错误的地方。
To find errors in PHP:
要在PHP中查找错误:
at the very top of the page add these lines:
在页面的最顶部添加以下行:
///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");
Now run your script, and (S)FTP to your server space and find the web folder you have and in it should be a file called "php-errors.log", download it and open it with a code program or a notepad, and it will output verious errors from PHP.
现在运行你的脚本,然后(S)FTP到你的服务器空间,找到你拥有的web文件夹,里面应该是一个名为“php-errors.log”的文件,下载并用代码程序或记事本打开它,它将从PHP输出错误的错误。
And give us the feedback you get from this file.
并向我们提供您从此文件中获得的反馈。