Send e mails PHP/HTML


This post is talking about the PHP email function from a HTML page.




First of all HTML code below ........

<form id="BuyerContact" name="BuyerContact" action="BuyerReqEmail.php" method="post" onSubmit="return validate()" >
    <table width="102%" align="center">
<tr>
<td width="51" height="45"> </td>
<td width="49"><span class="style1"> <span class="style2"> <span class="style3">
 <label><span class="style6">Name</span> </label>        </td>
<td width="354">
 <input name="Name" type="text"  style="width:250px;" />    </td>

<td width="8" height="45"> </td>
<td width="267"><span class="style1"> <span class="style2"> <span class="style3">
 <label><span class="style6">Areas Interested In </span></label>        </td>
<td width="248">
 <input name="AreasInterestedIn " type="text" style="width:250px;" />    </td>
</tr>

<tr>
<td width="51" height="43"> </td>
<td width="49"><span class="style1"> <span class="style2"> <span class="style3">
 <label><span class="style6">E Mail </span> </label>        </td>
 <td width="354"><input name="Email" type="text" style="width:250px;" /></td>

<tr>

<td><input  type="submit" style="width:100px;"  value="Submit" />
<input name="Submit3" type="button" style="width:100px;" title="Reset" value="Reset"/></td>

</tr>
</table>
           </form>

End of HTML code
Then PHP code of the BuyerReqEmail.php file



<?php

if(isset($_POST['Email'])) {
   
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "your email address here";
    $email_subject = "Your email subject line";
   
    
    $first_name = $_POST['Name']; // required
    $email_from = $_POST['Email']; // required
 
    $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 .= "Email: ".clean_string($email_from)."\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. Go to <a href="index-1.html"> Home page </a>


<?php
header("Location: your URL ");

}
?>


Comments

Popular Posts