Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So i have a working php mail send function, however i found a script online that performs a nice animation once its submitted instead of redirecting to a html page. So the php mail works and sends an email when i do not use the javascript. Once i use the javascript (include it in my html code), the animation (js) executs, but it doesnt send the email anymore.
I think that the javascript is not waiting for the php script to finish or something so thats why the email doesnt send... but not sure.. Please help!

Here are a few excerpts of the relevant code:

HTML:

<h4> Contact US </h4><span class="liner"></span>
<p>Leave us your feedback, comments or questions!</p>
<form action="testemail.php?" method="post" name="Contact" id="contactForm">
 <div class="clearfix">

 <div class="grid"><input type="text" name="senderName" id="senderName" placeholder="Name *" class="requiredField" /></div>
 <div class="grid"><input type="text" name="senderEmail" id="senderEmail" placeholder="Email Address *" class="requiredField email" /></div>
 </div>
 <div><textarea name="message" id="message" placeholder="Message *" class="requiredField" rows="8"></textarea></div>
                            <input type="submit" id="sendMessage" name="submit" value="Send Email" />
                            <span>  </span>
</form><!-- end form -->

JS:

// Ajax Contact
if ($("#contactForm")[0]) {
    $('#contactForm').submit(function () {
        $('#contactForm .error').remove();
        $('.requiredField').removeClass('fielderror');
        $('.requiredField').addClass('fieldtrue');
        $('#contactForm span strong').remove();
        var hasError = false;
        $('#contactForm .requiredField').each(function () {
            if (jQuery.trim($(this).val()) === '') {
                var labelText = $(this).prev('label').text();
                $(this).addClass('fielderror');
                $('#contactForm span').html('<strong>*Please fill out all fields.</strong>');
                hasError = true;
            } else if ($(this).hasClass('email')) {
                var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
                if (!emailReg.test(jQuery.trim($(this).val()))) {
                    var labelText = $(this).prev('label').text();
                    $(this).addClass('fielderror');
                    $('#contactForm span').html('<strong>Is incorrect your email address</strong>');
                    hasError = true;
                }
            }
        });
        if (!hasError) {
            $('#contactForm').slideDown('normal', function () {
                $("#contactForm #sendMessage").addClass('load-color');
                $("#contactForm #sendMessage").attr("disabled", "disabled").val('Sending message. Please wait...');
            });
            var formInput = $(this).serialize();
            $.post($(this).attr('action'), formInput, function (data) {
                $('#contactForm').slideUp("normal", function () {
                    $(this).before('<div class="notification-box notification-box-success"><p><i class="icon-ok"></i>Thanks!</strong> Your email was successfully sent. We check Our email all the time, so we should be in touch soon.</p></div>');
                });
            });
        }
        return false;
    });
}

PHP: (i removed my information obviously)

 <?php



if(isset($_POST['submit'])) 
{

$message=
'Full Name: '.$_POST['senderName'].'<br />
Subject:    '.$_POST['subject'].'<br />
Email:  '.$_POST['senderEmail'].'<br />
Comments:   '.$_POST['message'].'
';


require 'PHPMailer/class.phpmailer.php';

$mail = new PHPMailer(true); //New instance, with exceptions enabled

//$body             = file_get_contents('contents.html');
$body             = preg_replace('/\\\\/','', $body); //Strip backslashes

$mail->IsSMTP();                           // tell the class to use SMTP
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = x;                    // set the SMTP server port
$mail->Host       = "x"; // SMTP server
$mail->Username   = "x";     // SMTP server username
$mail->Password   = "x";            // SMTP server password

$mail->IsSendmail();  // tell the class to use Sendmail

$mail->AddReplyTo("[email protected]","First Last");

$mail->SetFrom($_POST['senderEmail']);

$to = "[email protected]";

$mail->AddAddress($to);

$mail->Subject  = "Contact Form Submitted";

//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap   = 80; // set word wrap


$mail->MsgHTML($message);

$mail->IsHTML(true); // send as HTML

$mail->Send();
}
?>
share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.