Hello: I just joined so still wet behind the ears. I can read and tweak code, but I'm no programmer. I've been using a PHP script to create a contact form, display a message on Send and to send html email. script begins with: Code: <? function SafeHTML($string) { $string = stripslashes($string); $string = htmlspecialchars($string); return nl2br($string); } function ValidateEmail($Email){ $result = ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $Email); if ($result){ return true; } else { return false; } } $subject = $_POST['subject']; $subject = SafeHTML($subject); $name = $_POST['name']; $name = SafeHTML($name); $email = $_POST['email']; $telephone = $_POST['telephone']; $telephone = SafeHTML($telephone); $message = $_POST['message']; $message = SafeHTML($message); $contact = $_POST['contact']; $contact = SafeHTML($contact); switch($_GET[action]) { case "check"; if(strlen($subject) > 0 && strlen($name) > 0 && strlen($telephone) > 0 && strlen($email) > 0 && strlen($message) > 0 && !strstr($message, "http") && !strstr($message, "href") && ValidateEmail($email) == true) { $body= followed with html email format then Code: ; $headers = "From: $name <$email>\r\n"; $headers.="Content-type: text/html\r\n"; mail("client name <[email protected]>","New email from your website",$body, $headers); print "<div class='thanks'><p>Thank you for your email, <strong>$name</strong>.</p> </div>"; } else { print "<p class='star'><strong>You did not fill out all the required fields ( marked with * ) or you have entered an invalid email address. Please check the form and resubmit</strong></p>"; include("contactform.php"); } break; default: include("contactform.php"); break; } ?> How do I add a conditional statement in the $headers mail part to redirect mail based subject? Any assistance is much appreciated. thank you. kp
Do you mean something like this? PHP: if(stristr($subject, 'blabla') === FALSE) { // string not found in subject $headers = ...;} else { // string found in subject $headers = ...;}
edirect mail based on subject line Thank you so much for replying. Actually, falko, the subject will be a drop down, but of the the options is for solicitation. if chosen, i want the email to go to my junk folder immediately. but maybe the code you provided can still work if i make the change below? Code: if(stristr($subject, 'blabla') === TRUE) { // string not found in subject $headers = <[email protected]>; } else { // string found in subject $headers = <[email protected]>;
Use PHP: if(stristr($subject, 'blabla') === TRUE) { // string not found in subject $to_address = '[email protected]'; } else { // string found in subject $to_address = '[email protected]'; } and then pass $to_address as the first parameter to PHP's mail() function.