Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with contact form.

    Hi everyone, I'm trying to create a contact form with a simple validation question (what is 2+2) because I've been getting a lot of spam e-mails. I want it to just display a popup box on the same page saying that the message was either sent successfully, not sent, or they got the question wrong.

    Unfortunately I keep getting errors with it and I can't seem to figure it out. Any help?

    HTML:


    Code:
    <form id="contactus" method="post" action="contactengine.php">
        <p>contact</p>
        <label for="Name">name:</label>
        <input type="text" name="name" id="name" placeholder="e.g., John Doe" />
    
         <label for="Email">e-mail:</label>
    
        <input type="text" name="email" id="email" placeholder="johndoe@example.com"/>
    
        <label>what is 2+2? (anti-spam)</label>
        <input name="spam" placeholder="">
    
        <label for="Message">message:</label>
        <textarea name="message" id="message" placeholder="Send us any questions,       comments, or ideas you may have!"></textarea>
    
        <input type="submit" name="submit" value="Submit" id="submit" />
    </form>

    PHP:
    PHP Code:
    <?php
    $name 
    $_POST['name'];
    $email $_POST['email'];
    $message $_POST['message'];
    $from '******';
    $to '********'
    $subject 'Message from a site visitor.';
    $body "From: $name\nE-Mail: $email\nMessage:\n $message"; /
    if (
    $_POST['submit'] && $spam === '4') { 

    if (
    mail ($email$subject$body)) { 
    ?>
    <script language="javascript" type="text/javascript">
    alert('Thank you for the message. We will contact you shortly.');
    window.location = 'index.php';
    </script>
    <?php 
    } else { //end of PHP, start of JS ?>
    <script language="javascript" type="text/javascript">
    alert('Something went wrong! Please go back and try again.');
    window.location = 'index.php';
    </script>
    <?php //end of JS, start of PHP
    }
    } else if (
    $_POST['submit'] && $spam != '4') { 
    ?>
    <script language="javascript" type="text/javascript">
    alert('You answered the anti-spam question wrong! Please go back and try again.');
    window.location = 'index.php';
    </script>
    <?php //end of JS start of PHP
    }
    ?>
    Last edited by vwhatizthiz; 07-24-2012 at 06:38 PM.

  • #2
    New Coder
    Join Date
    Mar 2012
    Posts
    41
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Unfortunately I keep getting errors with it and I can't seem to figure it out. Any help?
    What errors are you getting?

  • #3
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hackarchives View Post
    What errors are you getting?
    I get the error that I answered the anti-spam question incorrectly, even though I put 4.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    If that's your whole code, I don't see where $spam is being set. That seems like the issue.

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    PHP Code:
    //add 
    $spam $_POST['spam']; 

  • #6
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, so currently I have this PHP:

    PHP Code:
    <?php
    $name 
    $_POST['name'];
    $email $_POST['email'];
    $message $_POST['message'];
    $spam $_POST['spam']; 
    $from 'edited out';
    $to 'edited out'
    $subject 'Message from a site visitor.';
    $body "From: $name\nE-Mail: $email\nMessage:\n $message"
    if (
    $_POST['submit'] && $spam === '4') { 

    if (
    mail ($name$email$message)) { 
    ?>
    <script language="javascript" type="text/javascript">
    alert('Thank you for the message. We will contact you shortly.');
    window.location = 'index.php';
    </script>
    <?php 
    } else { //end of PHP, start of JS ?>
    <script language="javascript" type="text/javascript">
    alert('Something went wrong! Please go back and try again.');
    window.location = 'index.php';
    </script>
    <?php //end of JS, start of PHP
    }
    } else if (
    $_POST['submit'] && $spam != '4') { 
    ?>
    <script language="javascript" type="text/javascript">
    alert('You answered the anti-spam question wrong! Please go back and try again.');
    window.location = 'index.php';
    </script>
    <?php //end of JS start of PHP
    }
    ?>
    But for some reason I'm not getting the e-mails. I checked the address it's being sent to and I even checked the spam folder, but no dice. In fact, the e-mail was actually sent to the 'from' email address. Help?

    Is it something with my HTML?

    Code:
    <form id="contactus" method="post" action="contact.php">
    	<p>contact</p>
    		<label for="Name">name:</label>
    		<input type="text" name="name" id="name" placeholder="e.g., John Doe" />
    					
    		<label for="Email">e-mail:</label>
    					
    		<input type="text" name="email" id="email" placeholder="johndoe@example.com"/>
    					
    		<label>what is 2+2? (anti-spam)</label>
    		<input name="spam" placeholder="">
    					
    		<label for="Message">message:</label>
    		<textarea name="message" id="message" placeholder="Send us any questions, comments, or ideas you may have!"></textarea>
    					
    		<input type="submit" name="submit" value="Submit" id="submit" />
    </form>

  • #7
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    mail is:

    PHP Code:
            $to $_POST['email'];
            
    $subject "Test mail";
            
    $message "here";
            
    $from "abc.sample@gmail.com";
            
    $headers "From:" $from;
                
    mail($to,$subject,$message,$headers); 

    see this post:

    Sending email id with php and mysql.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •