A PHP question...

lersheelershee Keeper of JSterling Heights, MI Icrontian
Hey guys and gals - I'm having an issue with a PHP form and I knew exactly where I should go. :-)

I'm working on a website for a friend of mine, and she wanted a form on her site (i.e. Name, Email, Phone number, etc.) That was easy to do in HTML, but then to submit it via email you had to know a PHP script. So, I researched online and actually learned how to do the code with a YouTube video. Everything seems to work, but when I fill this out and send it to my address (just to test it out), it sends it, but in my email there's nothing on the message. No name, no email, no nada. I watched the video again and it *seems* that I did everything right. So, someone tell me: WHAT DID I SCREW UP?!?

Thanks in advance. :-)

Comments

  • pragtasticpragtastic Alexandria, VA Icrontian
    Could you post the code snippet that sends the email?
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    edited May 2013
    Sure! Here's the PHP:

  • PirateNinjaPirateNinja Icrontian
    Are you including the message within the mail function?
    mail("$mailto","$subject","$message","$headers");

    Please make sure to include your headers when you paste the code, that could be the issue.
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    No! Where do I put that?

    Are you including the message within the mail function?
    mail("$mailto","$subject","$message","$headers");

    Please make sure to include your headers when you paste the code, that could be the issue.

  • LincLinc Owner Detroit Icrontian
    You're assigning the POST variables to variables with different names than you are using. For instance, you set $nameField but then refer to $name when building the Body.

    JBoogaloo
  • LincLinc Owner Detroit Icrontian
    Be sure to use the 'C' button in the comment editor to wrap code when you paste it :) Fixed.
    JBoogaloo
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    Lincoln said:

    Be sure to use the 'C' button in the comment editor to wrap code when you paste it :) Fixed.

    Wait, so... I just copy and paste it? That's it?

  • PirateNinjaPirateNinja Icrontian
    What @Lincoln said is true, if you fix that and you still have issues we probably need to modify the headers variable and add some complexity to make it work. There are things like boundaries, and additional formatting that help email clients understand and display the body of your message.

    If you aren't sure, what Lincoln is saying is instead of:
    Name: $name

    you should have
    Name: $nameField


    and so on.

    $success = mail($webMaster, $emailSubject, $body, $headers);
    This is the function that actually sends your mail, so it is formatted properly and you send your message out with $body. So my earlier question is answered yes.
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    Well, shoot. I changed the stuff that you told me to change... and now I don't get any emails from the form. What happened?
  • PirateNinjaPirateNinja Icrontian
    Can you post your updated code?
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    edited May 2013
    Yes:

  • PirateNinjaPirateNinja Icrontian
    Just for future another thing Lincoln was saying was to press the little C on Icrontic itself when you are posting code. That way it formats nicely.

    To be clear, with your first attempt and initial code .. with the email you did receive ...
    Did you see Name: __________ , Email: ____________
    or was the body of the email literally 100% blank?
  • BobbyDigiBobbyDigi ? R U #Hats ! TX Icrontian
    Fixed the code wrap on the above post.

    When posting your code, paste it, then highlight it all and click the "C" button in the reply window. It is between the S and the little picture Icon.

    You should end up with at the beginning and at the end.

    -Digi
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian

    Just for future another thing Lincoln was saying was to press the little C on Icrontic itself when you are posting code. That way it formats nicely.

    To be clear, with your first attempt and initial code .. with the email you did receive ...
    Did you see Name: __________ , Email: ____________
    or was the body of the email literally 100% blank?

    The email I received before was the first one: Name:______ Email:_________
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    lershee said:

    Just for future another thing Lincoln was saying was to press the little C on Icrontic itself when you are posting code. That way it formats nicely.

    To be clear, with your first attempt and initial code .. with the email you did receive ...
    Did you see Name: __________ , Email: ____________
    or was the body of the email literally 100% blank?

    The email I received before was the first one: Name:______ Email:_________
    On pressing C - in order to post code on here, I press control + c. Is that not enough?
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    BobbyDigi said:

    Fixed the code wrap on the above post.

    When posting your code, paste it, then highlight it all and click the "C" button in the reply window. It is between the S and the little picture Icon.

    You should end up with at the beginning and at the end.

    -Digi

    Got it! Thank you!
  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    Just testing:

  • PirateNinjaPirateNinja Icrontian
    @lershee it sounds like the html you have for your form inputs do not have the right tags. The tags for each field need to match the POST info in php. For example:

    $_POST['firstname'];

    requires that your original HTML look something like this:




    So I would revert to your original PHP that you posted, which at least sent the email. Then double check your HTML to make sure your variables (or form data) are matching with your POST variables in PHP.

    ====
    Control-C just copies text in Windows, you need to press the button @BobbyDigi is referring to if you want to properly post code in the forum.

  • lersheelershee Keeper of J Sterling Heights, MI Icrontian
    Okay, here's the code for the HTML. It's in the first of 3 columns in a table:

    And yes - I totally got (by the 3rd or 4th time) that the "press C" was on the actual form itself here and not on the keyboard... oops... :-)
  • PirateNinjaPirateNinja Icrontian
    edited May 2013
    So it looks fine except that you are using checkboxes with the same name. Try this code, it isn't ideal for a large number of reasons but it should be functional:

    HTML


    Please tell us more about you!



    Name:


    Email:


    Phone:





    Which location are you interested in?
    Metamora


    Romeo





    Which programs are you interested in?


    (Select any that apply)


    Infant


    Toddler


    Preschool


    Grade school





    When would you need our care?


    Part time


    Full time



    Anything else you would like us to know?







    PHP







    Name: $nameField


    Email: $emailField


    Phone: $phoneField


    Location(s): $locationField, $locationField2


    Programs: $programField, $programField2, $programField3, $programField4


    Time: $timeField


    Comments: $commentsField
    EOD; /* Set headers and send the message */ $headers = "From: $emailField\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Display Results */ if ($success) { echo "Message Sent! "; echo "$body"; } else { echo "Sorry, something didn't work"; } ?>


    ===================

    If you see the message in your browser after submitting the form, that means there were no problems in the Mail() function. So check your spam folders, or any gmail filters you have to make sure it is not hiding somewhere.

    If you see "Sorry, something didn't work" you should contact your web host and ask them to enable php error reporting / logging so you can get a more helpful error message and we can find out what went wrong.
    JBoogaloo
Sign In or Register to comment.