ryguy26 Posted August 24, 2016 Share Posted August 24, 2016 I am rather green with PHP and am trying to use the PHPMailer some of you may be familiar with found on Github https://github.com/PHPMailer I am having a strange issue. My PHP Mailer only succeeds if accessed through Firefox. Chrome and Safari are a no go. Anyone who could give it a look over, it would be much appreciated!! Here is the HTML snippet for the form: <div class="col-2-third col-last"> <div id="contact-form-result" data-notify-type="success" data-notify-msg="<i class=icon-ok-sign></i> Message Sent Successfully!"></div> <form class="no-b-margin" id="template-contactform" name="template-contactform" action="include/sendemail.php" method="post"> <div class="form-process"></div> <div class="col-1-half"> <input type="text" id="template-contactform-name" name="template-contactform-name" value="" class="sm-form-control required" placeholder="Name"> </div> <div class="col-1-half col-last"> <input type="email" id="template-contactform-email" name="template-contactform-email" value="" class="required email sm-form-control" placeholder="Email"/> </div> <div class="clear"></div> <div class="col-full col-last"> <input type="text" id="template-contactform-website" name="template-contactform-website" value="" class="sm-form-control" placeholder="Website"> </div> <div class="clear"></div> <div class="col-full"> <textarea class="required sm-form-control" id="template-contactform-message" name="template-contactform-message" rows="6" cols="30" placeholder="Message"></textarea> </div> <div class="clear"></div> <div class="col-full hidden"> <input type="text" id="template-contactform-botcheck" name="template-contactform-botcheck" value="" class="sm-form-control"> </div> <div class="clear"></div> <div class="col-full"> <button class="button button-border button-reveal fright tright nomargin" type="submit" id="template-contactform-submit" name="template-contactform-submit" value="submit"><i class="fa fa-paper-plane"></i><span>Send Message</span></button> </div> <div class="clear"></div> </form> </div> and here is the php code: <?php require_once('phpmailer/class.phpmailer.php'); $mail = new PHPMailer(); if( isset( $_POST['template-contactform-submit'] ) AND $_POST['template-contactform-submit'] == 'submit' ) { if( $_POST['template-contactform-name'] != '' AND $_POST['template-contactform-email'] != '' AND $_POST['template-contactform-message'] != '' ) { $name = $_POST['template-contactform-name']; $email = $_POST['template-contactform-email']; $website = $_POST['template-contactform-website']; $message = $_POST['template-contactform-message']; $subject = isset($subject) ? $subject : 'New Message From Contact Form'; $botcheck = $_POST['template-contactform-botcheck']; $toemail = 'myemailremoved@gmail.com'; // Your Email Address $toname = 'ryan'; // Your Name if( $botcheck == '' ) { $mail->SetFrom( $email , $name ); $mail->AddReplyTo( $email , $name ); $mail->AddAddress( $toemail , $toname ); $mail->Subject = $subject; $name = isset($name) ? "Name: $name<br><br>" : ''; $email = isset($email) ? "Email: $email<br><br>" : ''; $website = isset($website) ? "Website: $website<br><br>" : ''; $message = isset($message) ? "Message: $message<br><br>" : ''; $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : ''; $body = "$name $email $website $message $referrer"; $mail->MsgHTML( $body ); $sendEmail = $mail->Send(); if( $sendEmail == true ): echo 'We have <strong>successfully</strong> received your Message and will get Back to you as soon as possible.'; else: echo 'Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . ''; endif; } else { echo 'Bot <strong>Detected</strong>.! Clean yourself Botster.!'; } } else { echo 'Please <strong>Fill up</strong> all the Fields and Try Again.'; } } else { echo 'An <strong>unexpected error</strong> occured. Please Try Again later.'; } ?> Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted August 24, 2016 Share Posted August 24, 2016 Since it works with one browser but not another, I expect it has nothing to do with the PHP code. Try adding echo('<pre>'.print_r($_POST,1).'</pre>'); at the top of your PHP. Are you getting the same data sent to the server? If not, maybe it has something to do with your browser configuration such as restricting cookies or JavaScript. Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 24, 2016 Share Posted August 24, 2016 (edited) Depending on a button name to be submitted for your script to work is wrong and will completely fail in certain circumstances, one being in IE. I suspect you are testing it on <= IE8. You need to use if ($_SERVER['REQUEST_METHOD'] == 'POST') Then do additional checks. Edited August 24, 2016 by benanamen Quote Link to comment Share on other sites More sharing options...
maxxd Posted August 24, 2016 Share Posted August 24, 2016 (edited) While you're following NotionCommotion's advice, look to see if Chrome and Safari are passing the submit button as part of the $_POST data. They probably are, but may not be. If not, you can remove the checks for that and replace it with if($_SERVER['REQUEST_METHOD'] == 'POST'){ @benanamen just beat me to it... Edited August 24, 2016 by maxxd Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 24, 2016 Share Posted August 24, 2016 Lol! We both have the same exact post time so you missed me by seconds. Still +1 for the right answer. Quote Link to comment Share on other sites More sharing options...
ryguy26 Posted August 24, 2016 Author Share Posted August 24, 2016 You guys are so awesome. Thank you for your help, I really appreciate it! I think we are getting close I went back to the HTML and saw this line- I changed "post" to "POST" in case that might help: <form class="no-b-margin" id="template-contactform" name="template-contactform" action="include/sendemail.php" method="post"> I added NotionCommotion's line and got the following array- it looks like the same data to me: Array ( [template-contactform-name] => test [template-contactform-email] => test@test.com [template-contactform-website] => www.test.com [template-contactform-message] => test [template-contactform-botcheck] => [template-contactform-submit] => submit ) Benanamen + Maxxd - sorry! I am rather green with PHP. I am more of a front design guy :X Which line/if statement gets replaced with the new code? Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 24, 2016 Share Posted August 24, 2016 The first if. Quote Link to comment Share on other sites More sharing options...
ryguy26 Posted August 24, 2016 Author Share Posted August 24, 2016 That did the trick! Have I mentioned how awesome you guys are? Thank you!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.