Enquiry Form with Email Function in PHP | PHP examples

Enquiry Form with Email Function

0 7657

To send the email, there should be four parameters - 'To', 'Subject', 'Message' and the last one is 'Header'. These four parameters have all the information to send the mail.

The script to send the email when a form is submitted, is :
<?php

if(isset($_POST['sub']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];

$msg="Name: ". $name . "<br>" . "Email Id: ". $email . "<br>" . "Phone No: ". $phone . "<br>" .
"Message: ". $message;

$to = "contact@ontimeinfotech.com";
$subject = "Inquiry Received";
$sender = "$email";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "from: " . $sender."\n";
if(mail($to, $subject, $msg, $headers))
{
echo "Email has been sent.";
}
else
{
echo "Error !!";
}
}

?>

<h1> Enquiry Form </h1> <br/><br/>

<form action="" method="post">
<input type="text" name="name" placeholder="Name" required><br><br>
<input type="email" name="email" placeholder="Email" required><br><br>
<input type="phone" name="phone" placeholder="Mobile" maxlength="10" required><br><br>
<textarea name="message" ></textarea><br><br>
<input type="submit" name="sub" value="Submit">

</form>

Copy and Paste above complete code and enjoy the PHP Email Function with HTML Inquiry Form. As per your requirement, you can change the design of form and can change the fields name also.



Best WordPress Hosting


Share:

SSL for business, from $12.88


Leave a Reply


Comments
    Waiting for your comments

Coding Tag WhatsApp Chat
Coding Tag WhatsApp Chat