简体   繁体   中英

smtp php email script not sending email

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?

<?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

[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

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.

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 Error reporting:

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:

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.

And give us the feedback you get from this file.

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