ScottAllenNet Posted March 21, 2012 Share Posted March 21, 2012 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", '[email protected]'); 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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/259405-form-snag/ Share on other sites More sharing options...
requinix Posted March 21, 2012 Share Posted March 21, 2012 "forte" $subject = "Contact Form: $subject"; Link to comment https://forums.phpfreaks.com/topic/259405-form-snag/#findComment-1329769 Share on other sites More sharing options...
Muddy_Funster Posted March 21, 2012 Share Posted March 21, 2012 Yip, what requininx said: just change this line to read $subject = "Contact Form: ".trim($_POST['subject']); Link to comment https://forums.phpfreaks.com/topic/259405-form-snag/#findComment-1329773 Share on other sites More sharing options...
ScottAllenNet Posted March 21, 2012 Author Share Posted March 21, 2012 Many, many thanks guys. Really appreciated - been a thorn in my side. Scott. Link to comment https://forums.phpfreaks.com/topic/259405-form-snag/#findComment-1329805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.