Getting feedback on email from web page by using PHP

We will discuss in this article that how can we get feedback on our email address from website.  Its a very simple and easy technique to get feedback and suggestions on your email address from your website feedback form or contact form. Here are some front end and back end codes which will be used. The front end coding includes a simple HTML form with the following fields, First_Name, Last_Name, Email_Address, Contact # and Comment.

Step-1:  Add this HTML code to your web page where you want to place.

<form name=”contactform” method=”post” action=”send-email.php”>
<div align=”center” style=”width: 641; height: 406″>
<center>
<table width=”465″ height=”342″ border=”1″ bordercolor=”#F2F2F2″ style=”border-collapse: collapse” cellpadding=”0″ cellspacing=”0″>
<tr>
<td valign=”top” height=”53″ width=”455″ colspan=”2″>
<p align=”center”>
<font face=”Times New Roman,serif” size=”4″ color=”#000080″>
<b>Send us your Feed back</b></font></p>
<p align=”center”>
<font face=”Times New Roman,serif” color=”#000080″ size=”3″>
(Please fill all * marks)</font></td>
</tr>
<tr>
<td valign=”top” height=”33″ width=”190″>
<b><font size=”3″ color=”#000080″ face=”Arial Unicode MS”>  <label for=”first_name”>First
Name </label>&nbsp; </font></b></td>
<td valign=”top” height=”33″ width=”265″>
<font color=”#000080″ size=”4″><b>  <input type=”text” name=”first_name” maxlength=”50″ size=”13″ style=”color: #000080; font-size: 10pt; border: 1px solid #C0C0C0″>
*</b></font></td>
</tr>
<tr>
<td valign=”top”” height=”33″ width=”190″>
<b><font size=”3″ color=”#000080″ face=”Arial Unicode MS”>  <label for=”last_name”>Last
Name </label>&nbsp; </font></b></td>
<td valign=”top” height=”33″ width=”265″>
<font color=”#000080″ size=”4″><b>  <input type=”text” name=”last_name” maxlength=”50″ size=”30″ style=”color: #000080; font-size: 10pt; border: 1px solid #BFBEBE”>
*</b></font></td>
</tr>
<tr>
<td valign=”top” height=”33″ width=”190″>
<b><font size=”3″ color=”#000080″ face=”Arial Unicode MS”>  <label for=”email”>Email
Address </label>&nbsp; </font></b></td>
<td valign=”top” height=”33″ width=”265″>
<font color=”#000080″ size=”4″><b>  <input type=”text” name=”email” maxlength=”80″ size=”30″ style=”font-size: 10pt; color: #000080; border: 1px solid #BFBEBE”>
*</b></font></td>
</tr>
<tr>
<td valign=”top” height=”38″ width=”190″>
<b><font size=”3″ color=”#000080″ face=”Arial Unicode MS”>  <label for=”telephone”>Telephone Number</label></font></b></td>
<td valign=”top” height=”38″ width=”265″>
<font color=”#000080″ size=”4″><b>  <!–webbot bot=”Validation” s-data-type=”Number” s-number-separators=”,.” i-maximum-length=”30″ –><input type=”text” name=”telephone” maxlength=”30″ size=”16″ style=”font-size: 10pt; color: #000080; border: 1px solid #BFBEBE”>
</b></font></td>
</tr>
<tr>
<td valign=”top” height=”113″ width=”190″>
<b><font size=”3″ color=”#000080″ face=”Arial Unicode MS”>  <label for=”comments”>Comments </label>&nbsp; </font></b></td>
<td valign=”top” height=”113″ width=”265″>
<font color=”#000080″ size=”4″><b>  <textarea name=”comments” maxlength=”1000″ cols=”25″ rows=”6″ style=”color: #000080; font-size: 10pt”></textarea>
*</b></font></td>
</tr>
<tr>
<td colspan=”2″ style=”text-align:center” height=”39″ width=”456″>
<font color=”#000080″ size=”4″><b>  <input type=”submit” value=”Submit” style=”color: #F2F2F2; font-weight: bold; font-size: 10pt; border: 3px solid #E8E8E8; background-color: #008000″></b></font></td>
</tr>
</table>
<p>&nbsp;</p>
</center>
</div>
</form>

Once you will add above code to your web page you will get a simple HTML form (shown below). You can add more fields in this form according to your needs and requirements.

feedbackform

 

Step-2:  Now add this php code in notepad file and save it as “send-email.php” and change the email address (highlight below) and add your email address through which you can get feedback’s.

<?php
if(isset($_POST[’email’])) {

// EDIT THIS LINE AND ADD YOUR EMAIL ADDRESS 
$email_to = “admin@ideascell.com“;
$email_subject = “feed back form”;

function died($error) {
// your error code can go here
echo “We are very sorry, there is an error appears in the form therefore it couldnot be submitted. “;
echo “These errors appear below.<br /><br />”;
echo $error.”<br /><br />”;
echo “Please go back and fix these errors and try again.<br /><br />”;
die();
}

// validation expected data exists
if(!isset($_POST[‘first_name’]) ||
!isset($_POST[‘last_name’]) ||
!isset($_POST[’email’]) ||
!isset($_POST[‘telephone’]) ||
!isset($_POST[‘comments’])) {
died(‘We are very sorry, there is an error appears in the form therefore it couldnot be submitted.’);
}

$first_name = $_POST[‘first_name’]; // required
$last_name = $_POST[‘last_name’]; // required
$email_from = $_POST[’email’]; // required
$telephone = $_POST[‘telephone’]; // not required
$comments = $_POST[‘comments’]; // required

$error_message = “”;
$email_exp = ‘/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/’;
if(!preg_match($email_exp,$email_from)) {
$error_message .= ‘Please enter a valid email address.<br />’;
}
$string_exp = “/^[A-Za-z .’-]+$/”;
if(!preg_match($string_exp,$first_name)) {
$error_message .= ‘Please enter a valid email address Name.<br />’;
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= ‘Please enter a valid email address Name.<br />’;
}
if(strlen($comments) < 2) {
$error_message .= ‘The Comments you entered do not appear to be valid.<br />’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;

function clean_string($string) {
$bad = array(“content-type”,”bcc:”,”to:”,”cc:”,”href”);
return str_replace($bad,””,$string);
}

$email_message .= “First Name: “.clean_string($first_name).”\n”;
$email_message .= “Last Name: “.clean_string($last_name).”\n”;
$email_message .= “Email: “.clean_string($email_from).”\n”;
$email_message .= “Telephone: “.clean_string($telephone).”\n”;
$email_message .= “Comments: “.clean_string($comments).”\n”;

// create email headers
$headers = ‘From: ‘.$email_from.”\r\n”.
‘Reply-To: ‘.$email_from.”\r\n” .
‘X-Mailer: PHP/’ . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

<!– include your own success html here –>

Thank you for contacting us. We will be in touch with you very soon. Regards: Admin ideascell.com

<?php

Now open your web page and use it, hopefully you will successfully run this form and get your visitor’s feedback on your email address. 🙂

Leave a Reply

Your email address will not be published.