Hello there, I'm afraid I'm a newbie and don't know much about PHP coding, although I can go in and edit and I can usually change values and such. I've done a lot of browsing and I've tried to read up a bit on W3 schools, however I'm struggling.
I have an info request form that has built in spam prevention (I found this form online) and I'm trying to figure out a way to integrate in some coding that will allow me to submit the form to different emails.
I've been looking around online and I found similar questions and solutions for this, however I really need to keep the spam prevention, and I'm really not sure how to merge my form with the solutions that I've found.
Here is my coding:
<?php
if (isset($_POST["op"]) && ($_POST["op"]=="send")) {
/******** START OF CONFIG SECTION *******/
$sendto = "email@whatever.com";
$subject = "Info Request for Company";
// Select if you want to check form for standard spam text
$SpamCheck = "Y"; // Y or N
$SpamReplaceText = "*content removed*";
// Error message prited if spam form attack found
$SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.
</font><br><b>Your IP Number of <b>".getenv("REMOTE_ADDR")."</b> has been logged.</b></p>";
/******** END OF CONFIG SECTION *******/
$name = $HTTP_POST_VARS['name'];
$email = $HTTP_POST_VARS['email'];
$message = $HTTP_POST_VARS['message'];
$headers = "From: $email\n";
$headers . "MIME-Version: 1.0\n"
. "Content-Transfer-Encoding: 7bit\n"
. "Content-type: text/html; charset = \"iso-8859-1\";\n\n";
if ($SpamCheck == "Y") {
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wastignt ime sending emails
if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();}
// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer
$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string
$name = preg_replace($pattern, "", $name);
$email = preg_replace($pattern, "", $email);
$message = preg_replace($pattern, "", $message);
// Check for the injected headers from the spammer attempt
// This will replace the injection attempt text with the string you have set in the above config section
$find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i");
$email = preg_replace($find, "$SpamReplaceText", $email);
$name = preg_replace($find, "$SpamReplaceText", $name);
$message = preg_replace($find, "$SpamReplaceText", $message);
// Check to see if the fields contain any content we want to ban
if(stristr($name, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
if(stristr($message, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
// Do a check on the send email and subject text
if(stristr($sendto, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
if(stristr($subject, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
}
// Build the email body text
$emailcontent = "
------------------------------
INFORMATION REQUEST FOR COMPANY
------------------------------
Name: $name
Email: $email
What is this regarding?: $info
Which location is this for?: $locale
Message: $message
Do they want to join the mailing list?: $Newsletter
_______________________________________
End of Email
";
// Check the email address enmtered matches the standard email address format
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) {
echo "<p>It appears you entered an invalid email address</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
}
elseif (!trim($name)) {
echo "<p>Please go back and enter a Name</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
}
elseif (!trim($message)) {
echo "<p>Please go back and type a Message</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
}
elseif (!trim($email)) {
echo "<p>Please go back and enter an Email</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
}
// Sends out the email or will output the error message
elseif (mail($sendto, $subject, $emailcontent, $headers)) {
echo "<br><br><p><b>Thank You $name</b></p><p>We will be in touch as soon as possible.</p>";
}
}
else {
?>
<form method="post"><INPUT NAME="op" TYPE="hidden" VALUE="send">
<table align="left" cellpadding="0">
<tr>
<td width="178"><p>Full Name:</p></td>
<td width="433">
<input name="name" type="text" size="40" maxlength="150">
</td>
</tr>
<tr>
<td><p>E-mail address:</p></td>
<td>
<input name="email" type="text" size="40" maxlength="150">
</td>
</tr>
<tr>
<td height="27">What is this regarding?</td>
<td><select name="info" id="info">
<option value="Employment">Employment</option>
<option value="Questions">Questions</option>
<option value="Comments">Comments</option>
<option value="Private Parties/Events">Private Parties/Events</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr>
<td height="32">Which location is this for?</td>
<td><select name="locale" id="locale">
<option value="Location1">Location1</option>
<option value="Location2">Location2</option>
<option value="Both">Both Locations</option>
</select></td>
</tr>
<tr>
<td height="29" colspan="2">Would you like to receive news, promotions, offers and more from Mezzo via email?
<select name="Newsletter" id="Newsletter">
<option value="No">No</option>
<option value="Yes">Yes</option>
</select> </td>
</tr>
<tr>
<td valign="top"><p>Comments:</p></td>
<td><textarea name="message" cols="50" rows="6"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" value="Send Message"></td></tr>
</table>
</form>
<?php } ?>
What I want to happen is for the submission to be sent to different emails based on which location is selected. If location1 is selected I want it to go to a different email than location2.
If there is anyone out there who can help me with this, I would be incredibly grateful.
Thank you for any and all help!