Jump to content

PHPMailer only works in Firefox


ryguy26

Recommended Posts

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.';
}

?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by benanamen
Link to comment
Share on other sites

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 by maxxd
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.