PDA

View Full Version : More than one recipient with PHP Form


Ricky55
07-03-2008, 07:36 PM
Hi

I mentioned about getting a form to send a message via SMS text the other day, well I now have this working via a relay company.

To get this working the form emails them using

mymobile@text.aql.com

This does work but could I set the form up to send to two recipients? I want to send it to the relay company and my own email address.

The script looks like this


<?php
$after = "thanks.html";
$oops = "oops.html";

if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD'] != "POST") {
exit("<p>You did not press the submit button; this page should not be accessed directly.</p>");
} else {
$exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javas cript|alert)/i";
$profanity = "/(beastial|bestial|blowjob|clit|cock|cum|cunilingus |cunillingus|cunnilingus|cunt|ejaculate|fag|felati o|fellatio|****|fuk|fuks|gangbang|gangbanged|gangb angs|hotsex|jism|jiz|kock|kondum|kum|kunilingus|or gasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|p orn|pussies|pussy|spunk|xxx)/i";
$spamwords = "/(viagra|phentermine|tramadol|adipex|advai|alprazol am|ambien|ambian|amoxicillin|antivert|blackjack|ba ckgammon|texas|holdem|poker|carisoprodol|ciara|cip rofloxacin|debt|dating|porn)/i";
$bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer)/i";

if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) {
exit("<p>Known spam bots are not allowed.</p>");
}
foreach ($_POST as $key => $value) {
$value = trim($value);

if (empty($value)) {
exit("<p>Empty fields are not allowed. Please go back and fill in the form properly.</p>");
} elseif (preg_match($exploits, $value)) {
exit("<p>Exploits/malicious scripting attributes aren't allowed.</p>");
} elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) {
exit("<p>That kind of language is not allowed through our form.</p>");
}

$_POST[$key] = stripslashes(strip_tags($value));
}

if (!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,6})$",strtolower($_POST['email']))) {
exit("<p>That e-mail address is not valid, please use another.</p>");
}

$recipient = "jasonhutchinson32@btinternet.com";
$subject = "Web Site Enquiry";

$message = "You've received an e-mail through your website form: \n\n";
$message .= "Name: {$_POST['name']} \n\n";
$message .= "Address: {$_POST['address']} \n\n";
$message .= "Postcode: {$_POST['postcode']} \n\n";
$message .= "Email: {$_POST['email']} \n\n";
$message .= "Vehicle: {$_POST['vehicle']} \n\n";
$message .= "Damage: {$_POST['damage']} \n\n";
$message .= "Contact: {$_POST['contact']} \n\n";


$headers = "From: <{$_POST['email']}> \n";
$headers .= "Reply-To: <{$_POST['email']}>";

if (mail($recipient,$subject,$message,$headers)) {
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">";
} else {
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">";
}
}
?>

edbr
07-04-2008, 01:11 AM
as i see it
if (mail($recipient,$subject,$message,$headers)) {
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">";
} else {
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">";
}
sends the mail so
if (mail($recipient2,$subject,$message,$headers)) {
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$after\">";
} else {
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$oops\">";
}

will send another mail wif you add
[$recipient2 = "your second emaill@your other domain.com";

Ricky55
07-04-2008, 07:54 AM
I will try it, edbr, you little beauty, you may just have solved both of my problems, I'll let you know.

Ricky55
07-04-2008, 10:50 AM
This didn't work mate, does anyone know how to get this script sending to two locations?

Ricky55
07-04-2008, 11:00 AM
Trying to be too technical here mate, I simply separated the email addresses with a comma and it worked.

Thanks for your help anyway,

edbr
07-05-2008, 07:23 AM
sorry rik 1 of 30,00 mistakes i made yesterday, rushing!
should just have been a mail() , not the if statement i added