Jump to content

Php Contact Form Thanks Msg Error


groupkits

Recommended Posts

hi! I am using following coding as a PHP + HTML contact form:-

 

<html>

<head>

</head>

<body>

<?php

if(isset($_POST['email'])){

$email = $_POST['email'];

$recipient = "myemail@myemail.com,";

$subject = "Contact Form Email Subject";

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

mail($recipient, $subject, $mailheader) or die("Error!");

 

 

$msg = "<font color='green' size='3'>Thank You for your message.</font>";

echo $msg;

}

?>

<form method="POST">

<p align="center">

Enter your valid email id:

<br>

<input type="text" name="email">

<br>

<input type="submit" value="Subscribe now!">

</form>

<?php

echo $msg;

?>

</body>

</html>

 

 

I am getting a problem: The text: [ Thank You for your message."; echo $msg; } ?> ] is showing up at the top of form even before submission.

The form is sending the email but it is not showing the text [ Thank You for your message. ] blow the form after sending email.

Link to comment
Share on other sites

Well seeing as you're echoing the message at the top of the page that would explain why you're getting it at the top although you're checking if it's set which is odd. Trying changing

 

EDIT: Tried this on my site and it works fine other than you're echoing in two places which leads me to believe you are not showing everything

Edited by ExtremeGaming
Link to comment
Share on other sites

I tried you code on my PC and it works fine except that it shows the thanks message twice. Once before the form, and the other after the form upon successful form submission. I have modified the code a bit, you may try it.

 

<html>
<head>
</head>
<body>
<?php
if (isset($_POST['submit'])) {

if ( empty($_POST['email'])
||
!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$_POST['email'])) {
$msg = 'please provide a valid email';
} else {

$email = $_POST['email'];
$recipient = "myemail@myemail.com";
$subject = "Contact Form Email Subject";
$message = "your email message";
$mailheader = "From: $email \n";
mail($recipient, $subject, $message, $mailheader) or die("Error!");
$msg = "<font color='green' size='3'>Thank You for your message.</font>";
}
}
?>
<form method="POST">
<p align="center">
Enter your valid email id: <br> <input type="text" name="email"> <br>
<input type="submit" name="submit" value="Subscribe now!">

</form>
<?php
echo $msg;
?>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.