Well my PHP contact us form is sending email too well
But I am getting 7 emails per submission
Problem is I have no idea why I am getting 7 emails per submission.
Any thoughts?
CODE
<?php
if(isset($_POST['Send'])){
$first_name =trim($_POST['first_name']);
$last_name=trim($_POST['last_name']);
$phone_number=trim($_POST['phone_number']);
$email=trim($_POST['email']);
$msg=trim($_POST['msg']);
$name=$first_name." ".$last_name;
if($first_name == '' ||$last_name =='' || $phone_number == '' || $email == ''|| $msg == '' ){
$merror = "<p style='color:red;'> * Kindly fill all Fileds<p>";
}else{
foreach($_POST as $value){
if(stripos($value, 'Content-Type:')!== FALSE || $_POST['Address']!== "" ) {
$merror = "<p style='color:red;'> * The information you have entered has a problem</p>";
}else{
require_once "class.phpmailer.php";
$mail= new PHPMailer();
if(!$mail->ValidateAddress($email)){
$merror = "<p style='color:red;'> * Please enter a valid email address</p>";
}else{
$email_body = "";
$email_body = $email_body . "Name: ". $name ."<br>";
$email_body = $email_body . "Phone: ". $phone_number. "<br>";
$email_body = $email_body . "Email: ". $email . "<br>";
$email_body = $email_body . "Message: " . $msg . "<br>";
$mail->SetFrom($email, $name);
$address = "s@example.co";
$mail->AddAddress($address, Trial);
$mail->Subject= "Ess contact form message ".$name;
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($email_body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo"<script>window.open('Contact.php','_self')</script>";
}
echo"<script>window.open('Contact.php?status=thanks','_self')</script>";
}
}
}
}
}
?>