Hello DANIWEB!
Haven't posted before... but find this site a good info resource... but I'm pulling my hair out with my php register code - don't know what I'm doing wrong... as the code i've written doesn't send on the site i'm working on...
Here's the code
<?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','university','course','message');
$required = array ('name','email','university','course','message');
$your_email = "miguel@test.co.uk";
$email_subject = "Web Registration: ".$_POST['subject'];
$email_content = "New Registration:\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";
}
}
if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>
I keep getting the message "PLEASE FILL IN REQUIRED FIELDS" But all the five fields have been filled in correctly.
When I amend the line
$values = array ('name','email','university','course','message');
$required = array ('name','email','university','course','message');
to be
$values = array ('name','email','message');
$required = array ('name','email','message');
It sends fine... but I'm missing the content from the 'University' and 'Course' fields....
Can anyone advise what the devil I'm doing wrong....
Many thanks
Miguel