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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:44:52+00:00 2026-05-30T15:44:52+00:00

I am making a feedback form for my website using php, I thought that

  • 0

I am making a feedback form for my website using php, I thought that it was working, but then it took an arrow to the code.

Anyways, the form has 4 fields: “name”, “email”, “subject”, and “message”.

I get the “Message failed” alert if all four fields have content.

Seeing as that is the case, I tested with content in 3 of the 4 fields, which gives me 4 combinations:

combo 1 - "name", "email", "subject"
combo 2 - "name", "email", "message"
combo 3 - "name", "subject", "message"
combo 4 - "email", "subject", "message"

The results were as follows:

combo 1 - "Thank you for your message."
combo 2 - "Thank you for your message."
combo 3 - "Message failed."
combo 4 - "Thank you for your message."

Here is the html code I am using:

<form action="contact.php" method="post">
  <input type="hidden" name="page" value="contact" />
  <input type="hidden" name="req" value="submit" />
  Your Name: <input type="text" name="name" />
  <br/>
  Your Email: <input type="text" name="email" />
  <br/>
  Subject: <input type="text" name="subject" size="69" />
  <br/>
  Message:
  <br/>
  <textarea cols="63" rows="8" name="message"></textarea>
  </br>
  <input type="submit" value="Send" />
  <input type="reset" value="Clear" />
</form>

And here is contact.php:

<?php
  $field_name = $_POST['name'];
  $field_email = $_POST['email'];
  $field_subject = $_POST['subject'];
  $field_message = $_POST['message'];

  $mail_to = 'email@my_website.com';
  $subject = 'Message from a site visitor '.$field_name;

  $body_message = 'From: '.$field_name."\n";
  $body_message .= 'E-mail: '.$field_email."\n";
  $body_message .= 'Subject: '.$field_subject."\n";
  $body_message .= 'Message: '."\n";
  $body_message .= $field_message;

  $headers = 'From: '.$field_email."\r\n";
  $headers .= 'Reply-To: '.$field_email."\r\n";

  $mail_status = mail($mail_to, $subject, $body_message, $headers);

  if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
  alert('Thank you for your message.');
  window.location = './contact.html';
</script>
<?php
  }
  else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed.');
window.location = './contact.html';
</script>
<?php
  }
?>

Is there anything wrong with the code? I don’t understand why it is doing this.

  • 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-30T15:44:54+00:00Added an answer on May 30, 2026 at 3:44 pm

    Great answer from Anton but I wanted to dig a little bit more into this and expand his answer.

    If you want to make sure someone sent the email, require it hardcoded with php (and html5 would be cool too, but this can be avoid so you still need php). I also deleted the javascript bit as it felt irrelevant there. This is what I would try and since it’s short I’d do it all in the same page. There are many subtle changes:

    <?php
    $field_name = $_POST['name'];
    $field_email = $_POST['email'];
    $field_subject = $_POST['subject'];
    $field_message = $_POST['message'];
    
    
    //If all required fields are filled
    if (!empty($field_name)&&!empty($field_email)&&!empty($field_message))
      {
      $mail_to = 'email@my_website.com';
      $subject = 'Message from a site visitor: '.$field_name;
    
      $body_message = 'From: '.$field_name."\n";
      $body_message .= 'E-mail: '.$field_email."\n";
      $body_message .= 'Subject: '.$field_subject."\n";
      $body_message .= 'Message: '."\n";
      $body_message .= $field_message;
    
      $headers = 'From: '.$field_email."\r\n";
      $headers .= 'Reply-To: '.$field_email."\r\n";
    
      $mail_status = mail($mail_to, $subject, $body_message, $headers);
    
      echo "Thank you for your message.";
      }
    
    //If not all required fields are filled display form again.
    else
      { ?>
      Please fill all the required fields.<br>
    
      <form action="" method="post">
      <input type="hidden" name="page" value="contact" />
      <input type="hidden" name="req" value="submit" />
    
      <?php //The php bits are to retrieve the valid fields ?>
      Your Name*: <input required type="text" value="<?php echo $field_name; ?>" name="name"/>
      <br/>
      Your Email*: <input required type="email" value="<?php echo $field_email; ?>" name="email" />
      <br/>
      Subject: <input type="text" name="subject" value="<?php echo $field_subject; ?>" size="69" />
      <br/>
      Message*:
      <br/>
      <textarea required cols="63" rows="8" name="message"><?php echo $field_message; ?></textarea>
      </br>
      <input type="submit" value="Send" />
      <input type="reset" value="Clear" />
      </form>
    
      <?php
      }
    ?>
    

    Otherwise, if you don’t care about who sends it, you could just put something like this

    $field_name = $_POST['name'];
    $field_email = $_POST['email'];
    if (empty($field_email)) $field_email="anonymous@MYPAGE.com";
    $field_subject = $_POST['subject'];
    $field_message = $_POST['message'];
    

    Last thing, I hope this is just a pseudo code as it doesn’t comply almost any html rule. You need < html > tags, < body > etc…

    Just tested and worked great (;

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

Sidebar

Related Questions

I'm thinking it's the placement of the C# code that is making my radio
I have a little experience in php and I am making a website for
Possible Duplicate: How to escape strings in MSSQL using PHP? I am making a
Making an adobe flex ui in which data that is calculated must use proprietary
Making UML sequence diagram in VS 2010RC I've observed that there is no activation
When making changes using SubmitChanges() , LINQ sometimes dies with a ChangeConflictException exception with
I am making a WPF-application.I have a datagrid with a column header that contains
I have this massive nested loop scenario that is calling the DB and making
I'm making an iphone app. All you need to know is that there is
I'm looking for some feedback, blog links, etc that offer some tips and tricks

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.