Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Problems with mail()!

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #32846
    BenColegate
    Participant

    Hey, having some right problems with jQuery and PHP and it’s made me sad! :(

    The scenario is I’ve got a contact form on my website and I’m basically emailing the collected data to my account. Easy!

    Till I hit a wall! All the data that I’m trying to get in the email, is only showing in the subject for the email.

    I’ll show you the code, see what you think. Probably a noob mistake or two!

    jQuery:


    $(function() {
    $(".button").click(function() {
    $('.error').hide();

    var full_name = $("input#full_name").val();
    var email = $("input#email").val();
    var question = $("textarea#question").val();

    var dataString = full_name + email + question;
    //alert (dataString);return false;

    $.ajax({
    type: "POST",
    url: "bin/process.php",
    data: dataString,
    success: function() {
    $("#contact_form").hide()
    $("#thank_you").fadeIn('slow')
    }
    });
    return false;
    });
    });

    process.php


    $name = $_REQUEST ;
    $email = $_REQUEST ;
    $message = $_REQUEST ;

    mail( "[email protected]",$email,$message);
    header( "Location: http://www.example.co.uk" );
    ?>

    Any help would be much loved!

    Ben

    #75494
    Johnnyb
    Member

    Have you tried adding a subject to your php file?:

    
    $name = $_REQUEST ;
    $email = $_REQUEST ;
    $subject = 'Website Contact Form';
    $message = $_REQUEST ;

    mail( "[email protected]",$subject,$email,$message);
    header( "Location: http://www.example.co.uk" );
    ?>

    It might be putting your info into the email subject as you don’t appear to be specifying one.

    #75495
    TT_Mark
    Member

    You’ve not named the variables you’re passing

    Think about the following line of code and what it’s actually doing:

      var dataString = full_name + email + question;

    If you have fullname ‘Mark’, email ‘[email protected]’ and question ‘How do I do this?’, the above code gives:

    var dataString = '[email protected] do I do this?'

    Your code should be

      var dataString = 'full_name=' + full_name + '&email=' + email + '&question=' + question;
    #75480
    BenColegate
    Participant

    The pair of you, are utter legends! The sad thing is, I had both solutions at separate times…

    Anyway, once again! Thank you! And much love!

    #75481
    TT_Mark
    Member

    I also massively suggest you filter your data!

    The way the script is, it’ll break if anyone adds some dodgy data like an apostrophe

    #75466
    BenColegate
    Participant

    Yeah, there previously was validation and stripslashing. Then I couldn’t get it to work. So I stripped all that out, looks like it’ll be going back in again!

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.