Jump to content

Recommended Posts

Hi I am a newbie with PHP. I created a contact form following a tutorial online and have uploaded the index.html and contact-form.php form to a server with php enabled.

 

I am getting an error message

 

Warning! Please fill all the fields. ”; } else { mail($to,$subject,$msg,”From:”.$email); echo “

 

I am wondering if anyone can advise me?

 

 

The PHP:
 

<?php
	$to="calming1@yahoo.co.uk";/*Your Email*/
	$subject="Message from the website";

	$date=date("l, F jS, Y");
	$time=date("h:i A");

	$name=$_REQUEST['name'];
	$email=$_REQUEST['email'];
	$message=$_REQUEST['message'];

	$msg="
		Message sent from website form on date  $date, hour: $time.\n	
		Name: $name\n
		Email: $email\n	
		Message: $message\n
		";
	if($email=="") {
	echo "<div class='alert alert-danger'>
			  <a class='close' data-dismiss='alert'>×</a>
			  <strong>Warning!</strong> Please fill all the fields.
		  </div>";
	} else {
	mail($to,$subject,$msg,"From:".$email);
	echo "<div class='alert alert-success'>
			  <a class='close' data-dismiss='alert'>×</a>
			  <strong>Thank you for your message!</strong>
		  </div>";
	}
?>

HTML

<form id="contact" class="form-inline" action="contact-form.php" method="post" accept-charset="utf-8">	
					<div class="form-group pull-left">
						<label class="sr-only" for="name">Name</label>
						<input type="text" class="form-control" id="name" placeholder="Name" name="name">
					</div>

					<div class="form-group pull-right">
						<label class="sr-only" for="email">Email</label>
						<input type="email" class="form-control" id="email" placeholder="Email" name="email">
					</div>

					<textarea class="form-control pull-left" rows="8" placeholder="Message" name="message"></textarea>

					<button type="submit" class="btn pull-right">Send email</button>
				</form> 
Link to comment
https://forums.phpfreaks.com/topic/300298-contact-form/
Share on other sites

Hmmm,

 

I copied your files and uploaded them to my server. They worked just fine when I filled in all the fields. When I didn't though the message came out with a bit of garbage at the start of it. That anchor tag I suspect. So I removed it. What is the purpose of the anchors in front of your messages, or don't you know?

 

PS - It is recommended to use the appropriate array to search for your inputs. Since you know it is coming from $_POST, why do you look in $_REQUEST?

Edited by ginerjm
Link to comment
https://forums.phpfreaks.com/topic/300298-contact-form/#findComment-1529541
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.