-4

The code of the Form is :-

  <form action="mail.php">
  <input class="input-text" type="text" name="name" value="Your Name *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
  <input class="input-text" type="text" name="email" value="Your E-mail *" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">
  <textarea class="input-text text-area" name="message" cols="0" rows="0" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;">Your Message *</textarea>
  <input class="input-btn" type="submit" value="send message">
  </form>

i have hosted the webpage but the form is not working. what else do I need to do to put it in functioning.

here is the php code:-

<html>
<body>
<?php 
$errors = '';
$myemail = 'xyz@abc.com.com';
if(empty($_POST['name'])  ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match("/ ^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = '$myemail';
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n ".
    "Email: $email_address\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'indes' page
header('Location: index.html');
}
?>

I have done the php part and uploaded it to the website too but still it doesn't send any mail from the contact form. i.e. it is not responding at all. Can I get any help now ?

1 Answers1

1

You need to have a way of collecting the submission when it is sent. Have a read through this site, will provide you with more information.

Essentially you need to have use something like PHP to collect the information and process it, either store it into a database or email it to yourself.

HTML & PHP Contact Form

mail.php

<?php
   $name    = $_POST['name'];
   $email   = $_POST['email'];
   $message = $_POST['message'];

   $to      = 'nobody@example.com';
   $subject = 'the subject';
   $headers = 'From: webmaster@example.com' . "\r\n" .
              'Reply-To: webmaster@example.com' . "\r\n" .
              'X-Mailer: PHP/' . phpversion();

   mail($to, $subject, $message, $headers);
?> 

   // Either insert into database or email to yourself.  You would want to look at sanitizing the inputs a bit and checking for valid email addresses. 

PHP mail()

Blinkydamo
  • 1,582
  • 9
  • 20