SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Zapppa's Avatar
    Join Date
    Aug 2009
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Contact form not getting through spam filter

    I am having issues getting a simple contact form getting past the junk filter and into the inbox. Is there something wrong with my code?

    I have tried to set the email to 'not junk' in the 2 different email providers, but no change.


    Here is my code:



    Code HTML4Strict:
        <form method="post" action="mail_.php">
     
                <label>Name</label>
                <input name="name" placeholder="Type Here">
     
                <label>Email</label>
     
                <input name="email" type="email" placeholder="Type Here">
     
                <label>Message</label>
                <textarea name="message" placeholder="Type Here"></textarea>
     
                <label>*What is 7+3? (Anti-spam)</label>
                <input name="human" placeholder="Type Here">
     
                <input id="submit" name="submit" type="submit" value="Submit">
     
            </form>

    Code PHP:
    <?php
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $from = 'From: Contact Form'; 
        $to = 'my_email@gmail.com'; 
        $subject = 'Hello';
        $human = $_POST['human'];
     
        $body = "From: $name\n E-Mail: $email\n Message:\n $message";
     
      $headers .= "Content-type: text/plain; charset=utf-8\n";
      $headers .= "From: website user<someone_from@mysite.com> \n";
     
     
    if ($_POST['submit']) {
        if ($name != '' && $email != '') {
            if ($human == '10') {				 
                if (mail ($to, $subject, $body, $from)) { 
    	        echo '<p>Your message has been sent!</p>';
    	    } else { 
    	        echo '<p>Something went wrong, go back and try again!</p>'; 
    	    } 
    	} else if ($_POST['submit'] && $human != '4') {
    	    echo '<p>You answered the anti-spam question incorrectly!</p>';
    	}
        } else {
            echo '<p>You need to fill in all required fields!!</p>';
        }
    }
     
    ?>


    Any help would be much appreciated.

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,176
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    I'm not sure, but I wonder if it would help to have an email address in the $from variable, such as:

    PHP Code:
    $from "From: $email"\r\n" "Reply-To: $email"
    Worth a try, anyhow. Also, the "Hello" in your subject line may well be a flag to the spam machine, too, as it's a common spam title.

    By the way, what does $human != '4' have to do with 7 + 3?

  3. #3
    SitePoint Addict Zapppa's Avatar
    Join Date
    Aug 2009
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haha sorry I changed my human validation number to be 10 and not 4, didnt update it.

    I have amended to code to look like this and it now works!

    Code:
    <?php
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $to = 'my@email.com'; 
        $subject = 'Hello';
        $human = $_POST['human'];
    			
        $body = "From: $name\n E-Mail: $email\n Message:\n $message";
    	
      	$headers .= "From: Website USER <someone_from@mysite.com>";
    
    				
    if ($_POST['submit']) {
        if ($name != '' && $email != '') {
            if ($human == '10') {				 
                if (mail ($to, $subject, $body, $headers)) { 
    	        echo '<p>Your message has been sent!</p>';
    	    } else { 
    	        echo '<p>Something went wrong, go back and try again!</p>'; 
    	    } 
    	} else if ($_POST['submit'] && $human != '10') {
    	    echo '<p>You answered the anti-spam question incorrectly!</p>';
    	}
        } else {
            echo '<p>You need to fill in all required fields!!</p>';
        }
    }
    
    ?>
    Seems to have sorted it.

    Thanks

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,176
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    Glad you sorted it ... though I like to have the user's email address set as the from / reply to, as it makes it easy to replay ... if that's what you want to do.


Bookmarks

Posting Permissions

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