PHP Email Contact Form Help Needed?

Reemi

New member
Hi, I have a simple php email form. For some reason it's not emailing the Company Name nor is the subject being sent. Can anyone help me figure out how can I let these values be emailed as well even though they are not required from the user.

Thank you!
Also is there a way to attach an html header to the email.
Thanks =)






<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','company','message');
$required = array('name','email','message');

$your_email = "[email protected]";
$email_subject = "New Website Message:".$_POST['subject'];
$email_content = "New Message:\n";

foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n\n";
}
}

if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message delivered! You will be contacted shortly. Thank you!';
} else {
echo 'ERROR!';
}
}
?>
 
Back
Top