Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7527519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:07:38+00:00 2026-05-30T04:07:38+00:00

I have a contact form on my website, which actually works :D The problem

  • 0

I have a contact form on my website, which actually works 😀
The problem is, that the email ends up in the spam folder. I have tried to do stuff with the header section, but nothing seems to work.

Can anyone help me with this?

thanks

<?php
    ini_set("display_errors", "0");
    $post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS );

    $name = $post_data["name"];
    $email = $post_data["email"];
    $phone = $post_data["phone"];
    $website = $post_data["website"];
    $message = $post_data["message"];



    # select data that needs validation
    $validate = array(
        'required'  => array($name,$email,$message),
        'validEmail'    => array($email),
        'validNumber'   => array($phone),
        'validAlpha'    => array($name)
    );
    $formcontent = "Name: $name \nE-Mail: $email \nPhone: $phone \nWebsite: $website \nMessage: $message \n";
    $formcontent = wordwrap($formcontent, 70, "\n", true);

    $recipient = "thomas.teilmann@gmail.com"; 
    $subject = "Contact Messenbrink.eu"; 

    /*$mailheader = "From: $email \r\n";**/

    $mailheader .= "Reply-To: $name <$email>\r\n"; 
    $mailheader .= "Return-Path: $name <$email>\r\n"; 
    $mailheader .= "Content-Type: text/plain\r\n"; 
    $mailheader .= "Organization: Sender Organization\r\n";
    $mailheader .= "MIME-Version: 1.0\r\n";
    $mailheader .= "Content-type: text/plain; charset=iso-8859-1\r\n";
    $mailheader .= "X-Priority: 3\r\n";
    $mailheader .= "X-Mailer: PHP". phpversion() ."\r\n";
    $mailheader .= "From: $name <$email>\r\n";  

    function sendMail() {
        global $formcontent, $recipient, $subject, $mailheader;
        mail($recipient, $subject, $formcontent, $mailheader);
    }

    # error messages
    $errorsMsgs = array(
        'required'  => 'Please fill out all required fields.',
        'validEmail'    => 'is an invalid email address.',
        'validNumber'   => 'is an invalid number.',
        'validAlpha'    => 'contains invalid characters. This field only accepts letters and spaces.'
    );

    $errorMarkup    = "<h1>We found a few errors :-(</h1><h2>Please fix these errors and try again</h2><ol>";
    $errorMarkupEnd = "</ol>";
    $successMarkup  = "<h1>Success!</h1><h2>Your form was sent successfully.</h2>";
    $backMarkup     = "<a href=\"" . $_SERVER['HTTP_REFERER'] . "\">Back to form</a>";

    # begin state
    $valid = true;

    # loop through fields of error types
    foreach ($validate as $type => $fields) {
        # loop through values of fields to be tested
        foreach ($fields as $value) {
            # throw error if value is required and not entered
            if ($type === 'required' && strlen($value) === 0) {
                $errorMarkup .= "<li>$errorsMsgs[$type]</li>";
                $valid = false;
                break;
            }
            else if (
                $type === 'validEmail'  && !filter_var($value, FILTER_VALIDATE_EMAIL) ||
                $type === 'validNumber' && !preg_match('/^[0-9 ]+$/', $value) ||
                $type === 'validAlpha'  && !preg_match('/^[a-zA-Z ]+$/', $value)
            ) {
                if (strlen($value) === 0) {break;} # skip check if value is not entered
                $errorMarkup .= "<li>\"$value\" $errorsMsgs[$type]</li>";
                $valid = false;
                continue;
            }
        }
    }

    if ($valid) {
        sendMail();
        $body = $successMarkup . $backMarkup;
        $title = "Form sent";
    } else {
        $body = $errorMarkup . $errorMarkupEnd . $backMarkup;
        $title = "Form errors";
    }

    # write html ouput
    echo "<!DOCTYPE html><head><title>$title</title><style type=\"text/css\">body{margin:100px;font:16px/1.5 sans-serif;color:#111}h1{font-size:32px;margin:0;font-weight:bold}h2{font-size:18px;margin:0 0 20px 0}ol,li{list-style-position:inside;padding-left:0;margin-left:0}</style></head><body>$body</body></html>";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:07:40+00:00Added an answer on May 30, 2026 at 4:07 am

    It has nothing to do with the PHP code but make sure that the email are being sent from a domain that is hosted on the server. That means it would be a bad idea to use your gmail address for sending though PHP. Every email that leaves the server needs to be signed and needs to have SPF records

    This is usually because in the DNS a correct SPF record has not been setup. This can be easily done depending on the software you use. If you use cPanel then this is pretty much a two step process.

    Some links:
    http://www.emailquestions.com/help-desk/2418-why-do-my-own-emails-go-into-spam.html
    http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=spf+records
    http://www.techtalkpoint.com/articles/setting-up-spf-records-in-cpanel-whm-and-namecheap/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my client's website (domain.com) we have a contact form which sends an email
I have a website with a contact form. User submits name, email and message
I have set up an AJAX contact form on a client's website. The problem
I have a contact form where the email is actually accessible in the source,
i have a PHP contact form that submits data, and an email...: <?php $dbh=mysql_connect
I have a contact form on my website, and everything works like a charm.
I have a contact form on a website (a general form: name , email
I have a website, and in the Contact section I have a form which
I have a simple contact form on a website that has 2 text fields,
I have form on my website which is contact form. I am using ReCaptcha

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.