Forums

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

Home Forums Back End Contact Form help

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #153563
    kalmykov
    Participant

    I am trying to use the PHP from Chris’ contact form https://css-tricks.com/examples/NiceSimpleContactForm2/ in my portfolio site live @ http://kovcreation.com/

    I’m so frustrated after trying many different solutions I just want it to work!!!

    Any help is greatly appreciated

    Form HTML
    `

                           <div class="touch">&nbsp;</div>   
    
                           <form id="contact_me_form" method="post" action="email.php">
    
                              <div class="error_contact" id="name_error">Name is Required</div>
                              <input type="text" placeholder="Your Name (required)" id="name" class="textbox" />
    
                              <input type="text" name="email" id="email" placeholder="Your Email (required)" class="textbox email">
    
                              <div class="error_contact" id="comment_error">Message is Required</div>                         
                              <textarea cols="25" rows="5" name="message" id="comment" class="textbox message" placeholder="Your Message ( Inquiry? , Freelance Work? , or Just to Say Hi...)"></textarea>
    
                              <input type="image" src="img/send.png" alt="Send Message" name="submit" class="button submit_btn">
    
                           </form>
    
                    </div>`
    

    form PHP
    <?php

    $EmailFrom = "[email protected]";
    $EmailTo = "[email protected]";
    $Subject = "Nice & Simple Contact Form by CSS-Tricks";
    $Name = Trim(stripslashes($_POST['Name']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Message = Trim(stripslashes($_POST['Message']));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print "";
    exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";

    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: ");

    // redirect to success page
    if ($success){
    print "";
    }
    else{
    print "";
    }
    ?>

    #153565
    __
    Participant

    I am trying to use the PHP from Chris’ contact form …

    Any help is greatly appreciated

    Help with what? Do you have a question?

    offhand suggestions:

    … if you have a question, describe it in detail. Tell us what you want to achieve, what you tried, and what happened (vs. what you expected to happen). “It doesn’t work” is a very useless thing to say; dumping code out onto the internet and saying “I give up, you fix it” is rude (even if you didn’t mean it to be).

    … If you really did give up and just want someone else to fix it, that’s fine – but you’re no longer asking for free advice; you’re looking for someone to hire.

    … sharing larger blocks of code on the discussion board doesn’t really work very well. It’s usually better to use a service like pastebin or make a gist on github.

    #153631
    kalmykov
    Participant

    I feel my post was clear. The contact form isn’t working. I want it to work. The code I posted is the code I’m using to try and make it work. I posted to see if someone could see an error in it. If you don’t know whats wrong thats fine but don’t go trolling on the forums wasting people’s time, THATS rude.

    #153639
    __
    Participant

    It is not my intent to waste your time, nor to be rude, nor to argue about those points. I am asking what problem you are trying to solve. The reason “it doesn’t work” is not helpful is because that is already a “given” – if it did work, you wouldn’t be asking in the first place.

    To explain why “not working” is not clear: How do you mean? What is the result? Are you getting blank page or other errors (and are you checking for errors)? Are you getting a success message but no email? Are you getting a blank (or garbled) email? Is the form not displaying correctly? Is it telling you there are validation errors, but there shouldn’t be? There is no way to determine any of this by looking at your code dump.

    As I also mentioned, it is difficult to even check for basic errors because of how your code is displayed in the comment. (The only obvious issue there would be the empty From: header in your email; but that doesn’t mean it’s your main problem, or even necessarily a problem at all.) Making a gist or posting on pastebin (or {your favorite service} ) would make that practical.

    I am perfectly willing (eager, in fact) to help people out with their problems. That’s why I frequent this forum. If you cannot “help yourself” and accept helpful advice and participate in finding answers to your question, then I will let you alone.

    #153643
    Alen
    Participant

    It’s always a good idea to use paste bin or whatever to showcase your code. This forum likes to chew up code when posted like that… for short snippets it’s fine if you use the Block Code! button right above the comment form.

    For long form, like you posted, requires some sort of service to help us, help you.

    One thing I notices is this:

    In your form you have this name="email" but in your PHP code you’re referring to it as $_POST['Email']. Notice the capital E should be lowercase.

    trolling on the forums wasting people’s time

    Not sure why you’re so confrontational. We’re trying to help you. We could as easily ignore your request.

    In fact YOU are wasting OUR time by not explaining your issue in greater detail. We are not mind readers and looking at the code you posted, we can not identify the issue.

    PS. @traq is one of the members on this forum always trying to help. So the trolling statement was bit rude. And I have to give props to @traq for maintaining his cool and still trying to help you.

    #153745
    kalmykov
    Participant

    I’m new to this whole forum thing. I’m usually able to figure things out on my own but this PHP language has me stumped. I’m not trying to be confrontational I’m just trying to get some constructive help.

    I’m barely a novice with PHP so I don’t know how to validate the form or trouble shoot it in anyway. The most specific I can be is that only the javascript works now upon hitting the submit button(it didn’t before I I fixed the capitalization issue and added the name attribute). No information is sent to my email whatsoever.

    I’ve never used pastebin or gist on github, so apologies if this gist isn’t in the most optimal format

    My biggest concern is getting the form to actually send the data inputed to my email.

    #153750
    Alen
    Participant

    Are you working locally? or Live (server)?

    #153755
    kalmykov
    Participant

    I’m working Live. I have WAMP running on my machine but it’s my understanding that the PHP script will execute but not actually send if you run it locally.

    #153756
    __
    Participant

    I’m new to this whole forum thing.

    No problem. Keep in mind that it is very difficult to tell what mood people are in just by reading their comments, so it’s very easy to jump to the conclusion that they’re being mean. Of course, this effect is amplified if you’re already upset/frustrated. It’s best to imagine that they meant what they wrote in the best possible way (even if you’re sure that they didn’t).

    At the top of your PHP script, add the following:

    error_reporting( -1 );
    ini_set( 'display_errors',1 );
    

    …then see if you get any error messages.

    I’ve never used pastebin or gist on github, so apologies if this gist isn’t in the most optimal format

    It’s great. So, next suggestion is to add some output after your call to mail(). Right now, you just have <meta> redirects*, so (since those pages may or may not be set up at this point) you may not get a good indication if it is successful or not. Something like

    if ($success){
        print "success";
    }
    else{
        print "failure";
    }
    

    is better for testing.

    * actually, there is no reason to use <meta> redirects at all. PHP has a header function that can do an actual http redirect, which will always be more reliable.

    The most specific I can be is that only the javascript works now upon hitting the submit button(it didn’t before I I fixed the capitalization issue and added the name attribute).

    Try removing the javascript for the time being. It may be preventing you from seeing what the PHP is doing (in fact, it may be preventing the PHP from doing anything in the first place).

    I have WAMP running on my machine but it’s my understanding that the PHP script will execute but not actually send if you run it locally.

    It will, if you have a mail server set up to listen to PHP. It’s just that most people don’t. mail doesn’t actually send email; it just looks for a mail server that it can submit the email message to. (It has no idea what happens after that.) If it doesn’t find one, “oh, well.”

    #153760
    kalmykov
    Participant

    Thanks for all the feedback. Here is my quest thus far:

    I took off all the java script and added

    error_reporting( -1 );
    ini_set( 'display_errors',1 );
    

    to the top of my PHP.

    I got a white page with this text upon submitting.

    Not Found
    The requested URL /bin/contactthanks.php was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an > > ErrorDocument to handle the request.

    Then I used you method for testing instead

    if ($success){ print "success"; }
     else{ print "failure"; }
    

    and i got a white page that just said “success”. I got all happy and rushed over to my inbox but nothing :(

    I tried all of this while it was live on the server b/c I don’t know how to set up a mail server.

    #153761
    __
    Participant

    and i got a white page that just said “success”. I got all happy and rushed over to my inbox but nothing :(

    Alright, good. Let’s look at how you’re sending your email. This time, instead of printing “success”, print this:

    if($success){
        print "EmailTo: $EmailTo<br>".
            "Subject: $Subject<br>".
            "Body: $Body<br>".
            "From: $emailFrom";
    }
    

    That way, we’ll be able to see what values you are actually using in your call to mail.

    But wait

    Before you do that, try adding crlf after your “From” header (it’s required):

    //  no!
    //  mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    
    //  yes!
    mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>\r\n");
    
    #153763
    Alen
    Participant

    404 error is Not Found. So your /bin/contactthanks.php does not exist, or you have linked to it wrong. Where is the form relative to the page you’re submitting to?

    Also, $success thing doesn’t send anything, it’s just for testing. Addition by subtraction. You’re limiting the number of thing that can go wrong.

    1. test if form is passing values first
    2. integrate validation
    3. format email
    4. send email

    Your process is failing at number 1. Get that working first.

    You should be using something like:

    $name = trim(stripslashes($_POST['name']));
    var_dump($name); // should print the value of Name
    

    Var Dump is a test to see what data is being passed.

    -Alen

    #153766
    kalmykov
    Participant

    Thank you again for you help in this.

    I change success to

    if($success){
        print "EmailTo: $EmailTo<br>".
            "Subject: $Subject<br>".
            "Body: $Body<br>".
            "From: $emailFrom";
    }
    

    and i get a white page that says:

    Notice: Undefined variable: Body in >/home/admin/public_html/bin/phpmailer.php on line 18

    Notice: Undefined variable: emailFrom in >/home/admin/public_html/bin/phpmailer.php on line 48
    EmailTo: [email protected]
    Subject: Nice & Simple Contact Form by CSS-Tricks
    Body: Name: Michael Anthony Kalmykov Email: [email protected] Message: >Test message
    From:

    I’m not sure what crlf does or where to put it. Is it supposed to go in the html where the form starts?

    <form id="contact_me_form" method="post" action="email.php">

    or somewhere in the PHP?

    #153767
    kalmykov
    Participant

    test if form is passing values first
    integrate validation
    format email
    send email

    Thanks Alen that’s super helpful. I just dove into this thing blindly w/out any structure or process at all. It’s crazy how little info is out there on this. I thought it’d be a common thing w/ plenty of resources but it’s not the case o.0

    I don’t actually want any other pages to open up upon submitting just for the bubble to pop up saying thanks, which is currently working on this form, so I’ve replaced

    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    

    with

    if($success){
        print "EmailTo: $EmailTo<br>".
            "Subject: $Subject<br>".
            "Body: $Body<br>".
            "From: $emailFrom";
    }
    else{
        print "failure";
    }
    

    for testing purposes

    #153768
    kalmykov
    Participant

    Haha I can be such an idiot.

    Nevermind about the
    mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>\r\n");

    I put it where it’s supposed to be and now what I get is

    Notice: Undefined variable: success in >/home/admin/public_html/bin/phpmailer.php on line 39
    failure

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