Reputation: 419
I've setup a php procedure that includes a phpmailer send that works just fine on my local machine, but it won't run any code after the send() command.
Here is the code that works fine locally and is almost identical to code that works fine live on my contact page:
$subject = "";
$subject .= "Welcome to Your Strength Coach!";
$body = "";
$body .= "
Hi " . $nameFirst . ",
<br><br>
Welcome to <a href=\"https://www.yourstrengthcoach.com/\">Your Strength Coach</a>!
<br><br>
Thank you for signing up. We look forward to being a part of your health and fitness journey.
<br><br>
Be sure to check out the Getting Started section on the Your Account page to get answers to the most common questions we receive. If you have any that aren't answered there, please feel free to email us at anytime. You can reach us at [email protected].
<br><br>
Thanks again,<br>
Brian Gwaltney, Creator
<br><br>
Be sure to check us out on <a href=\"https://www.facebook.com/YourStrengthCoach1/\">Facebook</a>, <a href=\"https://www.instagram.com/yourstrengthcoach/\">Instagram</a>, and <a href=\"https://www.pinterest.com/yourstrengthcoach/\">Pinterest</a>!";
$mail = new PHPMailer;
$mail->IsSMTP(); // Use SMTP
$mail->Host = "smtp.servergrove.com"; // Sets SMTP server
$mail->SMTPDebug = 2; // 2 to enable SMTP debug information
$mail->SMTPAuth = TRUE; // enable SMTP authentication
$mail->SMTPSecure = "tls"; //Secure conection
$mail->Port = 587; // set the SMTP port
$mail->Username = '**'; // SMTP account username
$mail->Password = '**'; // SMTP account password
$mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$mail->CharSet = 'UTF-8';
$mail->Encoding = '8bit';
$mail->Subject = 'New Message from Your Strength Coach Contact Page';
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->From = '[email protected]';
$mail->FromName = 'Your Strength Coach';
$mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$mail->AddAddress($email); // To:
$mail->isHTML(TRUE);
$mail->Body = $body;
$mail->Send();
$nextPage = '../profile';
LoginWithCookie($nextPage,$user);
Rather than continuing to the login function which redirects after creating a cookie, I get this instead:
2017-05-28 19:40:03 SERVER -> CLIENT: 220 smtp2.servergrove.com ESMTP Exim 4.72 Sun, 28 May 2017 19:40:03 +0000 2017-05-28 19:40:03 CLIENT -> SERVER: EHLO www.yourstrengthcoach.com 2017-05-28 19:40:03 SERVER -> CLIENT: 250-smtp2.servergrove.com Hello www.yourstrengthcoach.com [38.89.161.133] 250-SIZE 52428800 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP 2017-05-28 19:40:03 CLIENT -> SERVER: STARTTLS 2017-05-28 19:40:03 SERVER -> CLIENT: 220 TLS go ahead 2017-05-28 19:40:03 CLIENT -> SERVER: EHLO www.yourstrengthcoach.com 2017-05-28 19:40:03 SERVER -> CLIENT: 250-smtp2.servergrove.com Hello www.yourstrengthcoach.com [38.89.161.133] 250-SIZE 52428800 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP 2017-05-28 19:40:03 CLIENT -> SERVER: AUTH LOGIN 2017-05-28 19:40:03 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2017-05-28 19:40:03 CLIENT -> SERVER: aW5mb0B5b3Vyc3RyZW5ndGhjb2FjaC5jb20= 2017-05-28 19:40:03 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2017-05-28 19:40:03 CLIENT -> SERVER: MEJpZ1NlY3JldCk= 2017-05-28 19:40:04 SERVER -> CLIENT: 235 Authentication succeeded 2017-05-28 19:40:04 CLIENT -> SERVER: MAIL FROM: 2017-05-28 19:40:04 SERVER -> CLIENT: 250 OK 2017-05-28 19:40:04 CLIENT -> SERVER: RCPT TO: 2017-05-28 19:40:04 SERVER -> CLIENT: 250 Accepted 2017-05-28 19:40:04 CLIENT -> SERVER: DATA 2017-05-28 19:40:04 SERVER -> CLIENT: 354 Enter message, ending with "." on a line by itself 2017-05-28 19:40:04 CLIENT -> SERVER: Date: Sun, 28 May 2017 19:40:03 +0000 2017-05-28 19:40:04 CLIENT -> SERVER: To: [email protected] 2017-05-28 19:40:04 CLIENT -> SERVER: From: Your Strength Coach 2017-05-28 19:40:04 CLIENT -> SERVER: Subject: New Message from Your Strength Coach Contact Page 2017-05-28 19:40:04 CLIENT -> SERVER: Message-ID: 2017-05-28 19:40:04 CLIENT -> SERVER: X-Priority: 1 2017-05-28 19:40:04 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.23 (https://github.com/PHPMailer/PHPMailer) 2017-05-28 19:40:04 CLIENT -> SERVER: MIME-Version: 1.0 2017-05-28 19:40:04 CLIENT -> SERVER: Content-Type: text/html; charset=UTF-8 2017-05-28 19:40:04 CLIENT -> SERVER: 2017-05-28 19:40:04 CLIENT -> SERVER: 2017-05-28 19:40:04 CLIENT -> SERVER: Hi brian, 2017-05-28 19:40:04 CLIENT -> SERVER:
2017-05-28 19:40:04 CLIENT -> SERVER: Welcome to Your Strength Coach! 2017-05-28 19:40:04 CLIENT -> SERVER:
2017-05-28 19:40:04 CLIENT -> SERVER: Thank you for signing up. We look forward to being a part of your health and fitness journey. 2017-05-28 19:40:04 CLIENT -> SERVER:
2017-05-28 19:40:04 CLIENT -> SERVER: Be sure to check out the Getting Started section on the Your Account page to get answers to the most common questions we receive. If you have any that aren't answered there, please feel free to email us at anytime. You can reach us at [email protected]. 2017-05-28 19:40:04 CLIENT -> SERVER:
2017-05-28 19:40:04 CLIENT -> SERVER: Thanks again,
2017-05-28 19:40:04 CLIENT -> SERVER: Brian Gwaltney, Creator 2017-05-28 19:40:04 CLIENT -> SERVER:
2017-05-28 19:40:04 CLIENT -> SERVER: Be sure to check us out on Facebook, Instagram, and Pinterest! 2017-05-28 19:40:04 CLIENT -> SERVER: 2017-05-28 19:40:04 CLIENT -> SERVER: . 2017-05-28 19:40:04 SERVER -> CLIENT: 250 OK id=1dF42m-00015y-51 2017-05-28 19:40:04 CLIENT -> SERVER: QUIT 2017-05-28 19:40:04 SERVER -> CLIENT: 221 smtp2.servergrove.com closing connection
Any ideas what is going wrong?
Upvotes: 2
Views: 181
Reputation: 37770
There isn't anything going wrong with the mail part. This line:
2017-05-28 19:40:04 SERVER -> CLIENT: 250 OK id=1dF42m-00015y-51
means that your mail server accepted the message successfully.
What is likely to be a problem is that any headers issued after you have generated output (i.e. the debug log) will not be sent because it's too late by then. If you turn off debug output (SMTPDebug = 0
), the redirect will be able to work.
Upvotes: 1