1

I am trying to make a email send in a pop up on my site that you can see with the link below: http://www.madaxedesign.co.uk

However it redirects perfectly to the thank you message however after it has redirected it does not implement the PHP. Below I have shown the PHP, HTML and Jquery used for this contact form.

HTML:

<form id="submit_message" class="hide_900" action="/send.php" method="post">
            <div id="NameEmail">
                <div>
                    <label for="name">Name*</label>
                    <input type="text" title="Enter your name" name="name"/>
                </div>
                <div>
                    <label for="email">Email*</label>
                    <input type="text" title="Enter your email address" name="email"/>
                </div>
            </div>
            <div id="MessageSubmit">
                <div>
                    <textarea maxlength="1200" title="Enter your message" name="message"></textarea>
                    <label for="message">Message</label>
                </div>
                <div class="submit">
                    <input type="submit" value="Submit"/>
                </div>
            </div>
        </form>

PHP:

 <?php 
 $name = $_POST['name'];
 $email = $_POST['email'];
 $message = $_POST['message'];
 $formcontent="From: $name \n Message: $message";
 $recipient = "maxlynn12@gmail.com";
 $subject = "Email From Madaxe";
 $mailheader = "From: $email \r\n";
 mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
 header('Location: /thanks.html');
 exit();
 ?>

Jquery:

        $('form#submit_message').live('submit', function() {
        $('#popup').load('/thanks.html');
        return false;
    }); 

I was wondering if anyone could quickly look and see if I am missing anything obvious that I can quickly fix or even point me in the right direction.

Thanks

MaxwellLynn
  • 880
  • 5
  • 23
  • 46
  • what is the purpose of return false in your statement – kumar May 07 '13 at 10:09
  • Your form is open to mail header injection. Always check the from-address if it is valid, otherwise it's easy to inject `bla@bla\r\nBcc: spam@example.com`. – Marcel Korpel May 07 '13 at 10:09
  • in Jquery: try `return true` – Joddy May 07 '13 at 10:17
  • Which version of jQuery you're using? `live()` is deprecated now (in 1.9). – MMM May 07 '13 at 10:26
  • You probably need to return `true` instead `false`, but if you return `true`, the page will be reloaded and the popup wont be get loaded. Then, if you want this to function the way you expect, you might want to look on ajax form submission. – code-jaff May 07 '13 at 10:30
  • I've noticed also that even if the php fails it'll show the thank you message so im going to have to re-think how to do this.. – MaxwellLynn May 07 '13 at 10:33
  • For debugging remove the `header('Location: /thanks.html');` since it prevents the browser of showing you errors on the origin page. – powtac May 07 '13 at 10:40

4 Answers4

2

Your jQuery is interfering.

I think this might help, using AJAX to post your form: jQuery Ajax POST example with PHP

Community
  • 1
  • 1
lukeocodes
  • 1,192
  • 1
  • 16
  • 31
0

You do not need to your jquery code. actually it prevents your default action form action=send.php. and it does not pass your inputs to send.php

Amir
  • 4,089
  • 4
  • 16
  • 28
0

$.live() is deprecated in jQuery 1.9 and that's what you appear to be using. Please either downgrade or use an alternative function like .submit().

$('#submit_message').submit(function (e) {
    e.preventDefault();
    $('#popup').load('/thanks.html');
}

Also, it is crucial that you sanitise your $_POST inputs before using them for your e-mail headers, otherwise a hacker can inject bad things into your headers.

MMM
  • 7,221
  • 2
  • 24
  • 42
0

if you are trying to send mail through localhost you need to change some setting in php.ini file. Refer below link to do this.

http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/ 
Rickyrock
  • 328
  • 2
  • 4
  • 21