1

So I have a form that is submitted through jQuery AJAX and around 18 arguments are passed to a php file. Now whenever I try to submit the form, stack limit is reached with that many arguments. But the moment I cut off like half the arguments, the forms works fine and email is received. But the email I receive does not have any body.

AJAX:

$.ajax({
                    url: "sendemail.php",
                    method: "post",
                    data: {
                        name: name,
                        email: email,
                        number: number,
                        username: username,
                        country: country,
                        cname: cname,
                        ctype: ctype,
                        ctheme: ctheme,
                        domainname: domainname,
                        webhosting: webhosting,
                        seo: seo,
                        gadvertising: gadvertising,
                        cmarketing: cmarketing,
                        ptech: ptech,
                        details: details,
                        description: description
                    },
                    success: function () {
                        alert("Hey brotha");
                    }
                }).fail(function () {
                    $("#confdiv").html("<p class='alert alert-danger'>There was an error submitting your form. Please try again later or contact us at <a href='mailto:sobanr4@gmail.com'>EMAIL</a></p>");
                    window.scrollTo(0, 100);
                });

the php script is:

    <?php

if (isset($_POST['name']) && $_POST['name'] != "") {

    $to = "sobanr4@gmail.com";
    $subject = "Website Order Request";
    $headers = "From: <".$_POST['email'].">\r\n";
    $headers .= "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $body = "<html>
    <head>
        <title>Order Request - ".$_POST['name']."</title>
    </head>
    <body>
        <p>NAME: ".$_POST['name']."</p>
        <p>EMAIL: ".$_POST['email']."</p>
        <p>NUMBER: ".$_POST['number']."</p>
        <p>USERNAME: ".$_POST['username']."</p>
        <p>COUNTRY: ".$_POST['country']."</p>
        <p>COMPANY NAME: ".$_POST['cname']."</p>
        <p>TYPE: ".$_POST['ctype']."</p>
        <p>THEME: ".$_POST['ctheme']."</p>
        <p>DOMAIN NAME: ".$_POST['domainname']."</p>
        <p>WEB HOSTING: ".$_POST['webhosting']."</p>
        <p>SEO: ".$_POST['seo']."</p>
        <p>GOOGLE ADVERTISING: ".$_POST['gadvertising']."</p>
        <p>CONTENT MARKETING: ".$_POST['cmarketing']."</p>
        <p>PERMANENT TECHNICIAN: ".$_POST['ptech']."</p>
        <br><br><br>
        <p>DETAILS: ".$_POST['details']."</p>
        <br><br><br>
        <p>DESCRIPTION: ".$_POST['description']."</p>
    </body>
    </html>";

    if (mail($to,$subject,$$body,$headers)) {
        echo 1;
    } else {
        echo 0;
    };

}

?>

The form can be found here: http://www.henryspike.tk/testform

Parker Queen
  • 619
  • 2
  • 12
  • 27
  • There is no set limit for AJAX POST-values. Maybe there is another issue? You can have a look at this thread and see if you find something: http://stackoverflow.com/questions/20249587/is-it-any-limit-for-post-data-size-in-ajax – junkfoodjunkie Apr 15 '17 at 17:12
  • I have actually tested your form and I get this javascript error in the console: "TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement.". Debugging your javascript is difficult, because it is all on one line (in the live form, that is). – KIKO Software Apr 15 '17 at 17:16
  • Can you specify what kind of error is that? and how to deal with it? @KIKOSoftware – Parker Queen Apr 15 '17 at 17:17
  • I could if you didn't put all your javascript on one line. It is sort of minified. I cannot set decent breakpoints this way. Wait, when I look at the source code the javascript looks normal. Hold on... Ah, Firefox shows one line, Chrome doesn't... and it gives the error: "Uncaught RangeError: Maximum call stack size exceeded". Conclusion, you're using Chrome, or perhaps Safari. – KIKO Software Apr 15 '17 at 17:18
  • Take a look here: https://jsbin.com/hemomipedu/edit?js,output – Parker Queen Apr 15 '17 at 17:22
  • Why can't you just change your html name attribute to an array. I assume all this comes from an html form. This way you don't need to parse soo many arguments – Rotimi Apr 15 '17 at 17:25
  • @Akin maybe it isnt about memory as KIKOSoftware said. I think I am messing while getting values of some input fields. I will try to sort it out. – Parker Queen Apr 15 '17 at 17:29
  • Well, I cannot find the cause of the error, but I would normally use `serialize()` to submit a form. See: http://www.jstiles.com/blog/How%20To%20Submit%20a%20Form%20with%20jQuery%20and%20AJAX – KIKO Software Apr 15 '17 at 17:29
  • I looked up the error message, and it seems you're getting `val()` of a jquery object containing a HTML Dom-Element somewhere. To be honest, I don't know... sorry. – KIKO Software Apr 15 '17 at 17:32

2 Answers2

0

Ok, I think it must be the radio buttons.

You get their value like this:

var seo = $("#seo").val();
var gadvertising = $("#gadvertising").val();
var cmarketing = $("#cmarketing").val();
var ptech = $("#ptech").val();

But it should be like this:

var seo = $("#seo:checked").val();
var gadvertising = $("#gadvertising:checked").val();
var cmarketing = $("#cmarketing:checked").val();
var ptech = $("#ptech:checked").val();

I have not tested this... but it is easy for you to try.

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
0

SOLUTION:

All this mess and in the end the problem was that one of the variables in my javascript were misspelled as 'ctheme' instead of 'theme'.

And the blank email issue was resolved because I typed '$$body' instead of '$body'.

Anyways, thanks every one for help, especially @KIKOSoftware

P.S: I guess its a welcome to the world of programming.

Parker Queen
  • 619
  • 2
  • 12
  • 27