ive been using dreamweaver fo about a year now, i have managed to get create a form with a spam filter however on trying to add radio buttons and list menus to the form which are required to send an automatic reponse(send back a price list based on there selected options) i have hit a brick wall!
please can someone tell me if the method used below is anywhere near possible to achieve this.
foreach ($_REQUEST as $key=>$value) { filter_spam($bad_patterns,$value);}
$body = "We have recieved a specail offer booking:\n\n"; foreach($fields as $a => $b)
{$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);}
if($fname == '') {print "You have not entered your first name, please go back and try again";}
else {
if($lname == '') {print "You have not entered your surname, please go back and try again";}
else {
if($from == '') {print "You have not entered an email address, please go back and try again";}
else {
Was unsure if the adult and junior button should be request, I suppose it makes sense asone needs to be specified, when I attempt to submit the form I get an invalid code/unable to access screen. I haven't yet had a problem on other forms I created with the field array but I will use () from now on.
Now that i have changed the fields to $ _ REQUEST, when i send the form it repeats the following 10 times 'We encountered an error sending your mail, please notify info@myemail.co.uk'
Last edited by seanmarkham; 12-04-2011 at 11:22 PM..
You have a very weird error reporting setup there. I'm pretty sure that if a variable isn't set, and you check for a boolean like you are - if($send1) - it will return false. If you notice, you have 10 error messages there, but 11 send statements. My guess is that one of these sendmail's was successful, but you wouldn't know because the only acknowledgement is a header redirect - which won't work because you've already sent PHP output.
I would suggest a major rethink about how you're sending your mail. I really don't think you need all those mail function calls. You should build your email based on the user input so that you only need to format 1 mail function. That will make it a lot easier to report errors.
From what I can see, you most certainly can have 1 mail function. Upon reading your code in detail, you're not even using the mail function properly. You're currently sending the emails to the value in $from, instead of the value in $to.
That works perfectly, ive managed to add a separate button too that sends me an email if they wish to be added to a mailing list, might look into MySQL in the future.
Thank you for all your help, very much apprieciated
foreach ($_REQUEST as $key=>$value) { filter_spam($bad_patterns,$value);}
$body1 = "We have recieved a database entry:\n\n"; foreach($fields as $a => $b)
{$body1 .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);}
if($fname == '') {print "You have not entered your first name, please go back and try again";}
else {
if($lname == '') {print "You have not entered your surname, please go back and try again";}
else {
if($from == '') {print "You have not entered an email address, please go back and try again";}
else {
if($post == '') {print "You have not entered a postcode, please go back and try again";}
else {
if($address == '') {print "You have not entered an address, please go back and try again";}
else {
if($check1 == 'checked'){
switch($size){
case '1':
echo 'Please specify a group size';
break;
case '2':
$body = "adults 0 - 8";
break;
case '3':
$body = "adults 8 - 16";
break;
case '4':
$body = "adults 16 - 20";
break;
case '5':
$body = "adults 20 - 44";
break;
case '6':
$body = "adults 44+";
break;
}
}
else if($check2 == 'checked'){
switch($size){
case '1':
echo 'Please specify a group size';
break;
case '2':
$body = "juniors 0 - 8";
break;
case '3':
$body = "juniors 8 - 16";
break;
case '4':
$body = "juniors 16 - 20";
break;
case '5':
$body = "juniors 20 - 44";
break;
case '6':
$body = "juniors 44+";
break;
}
}
$return = mail($from, $subject2, $body);
if(!$return){
echo 'There was a problem sending the mail';
}
else {header( "Location: http://www.mysite.co.uk/contact_confirm.php" );}
if($data == 'checked'){mail($to, $subject, $body1);}
}
}
}
}
}
function filter_spam ($spam_patterns,$field) {
foreach ($spam_patterns as $v) {
if (preg_match("/$v/i",stripslashes($field))) {
die("Spam found in input, no email was sent.");
}
}
}
?>
Last edited by seanmarkham; 12-05-2011 at 12:33 PM..
Can i pick your brains again please BluePanther, i have ammended the sections on my code for the 0 -8, 8-16 categories etc, lets take the adult 0-8 for example, i have changed it to this
PHP Code:
case '2':
$body = "Thank you for your information request,
We are able to mix adult and junior kart sessions, to request a junior pricelist please follow the link below <a href=\"www.mysite.co.uk/request_priceguide.php\">Price Guide</a>
With 8 - 16 people you are able to participate in a group event. minimum age of 16 years for all group events)..."
The slashes won't appear in your email body - it's an escape character to tell PHP to ignore the quote marks.
Ah, I forgot you'll have to send the header 'content type' as well. If you plan on including html in all the emails, check if this works (it will also now send the email from the contact email):
foreach ($_REQUEST as $key=>$value) {
filter_spam($bad_patterns,$value);
}
$body1 = "We have recieved a database entry:\n\n";
foreach($fields as $a => $b){
$body1 .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}
if($fname == '') {
print "You have not entered your first name, please go back and try again";
}
else {
if($lname == '') {
print "You have not entered your surname, please go back and try again";
}
else {
if($from == '') {
print "You have not entered an email address, please go back and try again";
}
else {
if($post == '') {
print "You have not entered a postcode, please go back and try again";
}
else {
if($address == '') {
print "You have not entered an address, please go back and try again";
}
else {
if($check1 == 'checked'){
switch($size){
case '1':
echo 'Please specify a group size';
break;
case '2':
$body = "adults 0 - 8";
break;
case '3':
$body = "adults 8 - 16";
break;
case '4':
$body = "adults 16 - 20";
break;
case '5':
$body = "adults 20 - 44";
break;
case '6':
$body = "adults 44+";
break;
}
}
else if($check2 == 'checked'){
switch($size){
case '1':
echo 'Please specify a group size';
break;
case '2':
$body = "juniors 0 - 8";
break;
case '3':
$body = "juniors 8 - 16";
break;
case '4':
$body = "juniors 16 - 20";
break;
case '5':
$body = "juniors 20 - 44";
break;
case '6':
$body = "juniors 44+";
break;
}
}
$return = mail($from, $subject2, $body, $headers);
if(!$return){
echo 'There was a problem sending the mail';
}
else {
header( "Location: http://www.mysite.co.uk/contact_confirm.php" );
}
if($data == 'checked'){
mail($to, $subject, $body1, $headers);
}
}
}
}
}
}
function filter_spam ($spam_patterns,$field) {
foreach ($spam_patterns as $v) {
if (preg_match("/$v/i",stripslashes($field))) {
die("Spam found in input, no email was sent.");
}
}
}
?>
Took the chance to indent your code as well, look how much easier it is to read! PHP is a language that doesn't rely on indentation, but there are plenty that do so it's a very good idea to start it.
Last edited by BluePanther; 12-06-2011 at 12:28 AM..