Hi Guys,
PHP has never been my fortay and I have hit a real snag.
Please find below code for a simple PHP contact form. However, in the subject line of the email sent to me I would like it to show:
Contact Form: $subject - ($subject is what is currently displayed).
I know this is a simple fix however I have been messing about for hours and can't seem to get it right.
Any help would be greatly appreciated.
Best,
Scott.
<?php
define("WEBMASTER_EMAIL", 'contact@pearceresourcing.com');
error_reporting (E_ALL ^ E_NOTICE);
//////////////////////////////////////////////////////
function ValidateEmail($email)
{
$regex = '/([a-z0-9_.-]+)'. # name
'@'. # at
'([a-z0-9.-]+){2,255}'. # domain & possibly subdomains
'.'. # period
'([a-z]+){2,10}/i'; # domain extension
if($email == '')
return false;
else
$eregi = preg_replace($regex, '', $email);
return empty($eregi) ? true : false;
}
//////////////////////////////////////////////////////
$post = (!empty($_POST)) ? true : false;
if($post)
{
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = stripslashes($_POST['message']);
$error = '';
// Check name
if(!$name)
$error .= 'Name required! ';
// Check email
if(!$email)
$error .= 'E-mail required! ';
if($email && !ValidateEmail($email))
$error .= 'E-mail address is not valid! ';
// Check message
if(!$message)
$error .= "Please enter your message!";
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
echo 'OK';
}
else
echo '<div class="errormsg">'.$error.'</div>';
}
?>