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 7808505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:09:16+00:00 2026-06-02T03:09:16+00:00

I need a very simple, but effective PHP form handler that will work with

  • 0

I need a very simple, but effective PHP form handler that will work with this form:

<form id="contact" method="post" action="contact_handle.php">
<label for="name">Name:</label>
<input type="text" class="text_style" placeholder="John Doe" name="name" /><br />
<label for="email">Email:</label> 
<input type="email" class="text_style" placeholder="email@example.com" name="email" /><br />   
<label for="message">Subject:</label>
<textarea class="areawidth" rows="4" name="message" /></textarea><br />
<button id="contactbutton" type="submit">Submit</button>
</form>  

This is what I currently have but it doesn’t send an email and it doesn’t redirect like I intended. And I cant seem to figure out whats going on.

<?php  
$invalid = '';
$my_email = 'my@email.com'; 

// Validate input:
if(empty($_POST['name'])  ||
   empty($_POST['email']) ||
   empty($_POST['message']))
{
    $invalid.= "\n All fields are required";
}
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];   

// Validate email:
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email))
{
    $invalid .= "\n Invalid email address";
}

// Send email if no errors detected:
if( empty($invalid))
{
$to = $my_email;
$subject = "Contact form submission: $name";
$body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email\n Message:\n $message";
$headers = "From: $email\n";
$headers .= "Reply-To: $email";
mail($to,$subject,$body,$headers);  

//redirect to the thank you page:    
header('Location: contact_thanks.php');
}
?>    

When it is submitted it takes me to contact_handle.php that displays blank and fails to redirect.

  • 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-06-02T03:09:18+00:00Added an answer on June 2, 2026 at 3:09 am

    i think the redirect has to be the first output to the browser, so if anything else is being output it won’t work.

    why don’t you just include the thank you page rather than redirecting to it, ie.

    include 'contact_thanks.php';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize this may be a very simple question but I need to know
I have a very simple entry form. After a button is pressed, I need
My question is probably very simple but it could also be the case that
What I need is very simple but, searching the web, I didn't find any
This question may look to be very simple but i don't know the answer.
Okay, this is probably very simple but, I have the below checks (not at
very simple question but I couldn't find an answer for this: I have the
This maybe very simple but I cant seem to sort it out on my
This should be very simple but I could not find an exhaustive answer: I
I'm sure this is something very simple but I can't figure it out. I've

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.