Hi,
I have a form that sometimes sends incomplete info, some do come in complete.
The missing part of the incomplete ones are the info after this:
[php]$body .= “Dear " . $name . " " . $lastname . " thank you for your registration which will be finalized once payment of the fees has been confirmed (see fees & terms). \n
The following are the information you have provided. \n
Please kindly review them and in case of mistakes please contact this email. Do NOT register again.” . “\n \n”;[/php]
By looking at the error in the log file I get this:
PHP Warning: Invalid argument supplied for foreach() in /path/to/file/registrazione.php on line 63
Line 63 is this:
[php]foreach ($clean_post as $key => $value) {
$body .= $key . ': ’ . $value . “\n”;
} [/php]
Anyhow, since I believe that might be caused by something else I added to the code I post the whole code for you to kindly review:
[php]<?php
//MAIL HEADER INFORMATION
$EmailFrom = “site name”;
$EmailTo = “email to send form to”;
$Subject = “registration”;
// CLEANUP ANY NON-PRINTABLE OR UNWANTED CHARACTERS
function clean_text_string($string) { // FORCE IT TO ACCEPTABLE ESCAPABLE CHARACTERS ONLY
$new = trim(ereg_replace(’[^’ a-zA-Z0-9&!#$%()"+:?/@,_.-]’, ‘¿’, stripslashes($string)));
$new = ereg_replace(’ +’, ’ ', $new);
return ( $new );
}
// ITERATE OVER POST DATA
foreach ($POST as $key => $value) {
$clean_key = strtolower(clean_text_string($key));
if (substr($clean_key,0,1) == '’) continue; // SKIP FIELD NAMES THAT START WITH UNDERSCORE
$clean_value = clean_text_string($value);
if ($clean_value == ‘’) continue; // SKIP EMPTY FIELDS
$clean_post["$clean_key"] = $clean_value;
}
// NOW TEST FOR FIELDS THAT ARE REQUIRED
$required = array(); // ADD YOUR FIELDS AS NEEDED
$all_okay = TRUE;
foreach ($required as $key) {
if ($clean_post["$key"] == ‘’) {
echo “
$key is a required field\n”;
$all_okay = FALSE;
}
}
// TEST FOR MISSING INPUT
if (!$all_okay) {
$referer = $_SERVER[‘HTTP_REFERER’];
echo “
<a href=”$referer">Please click to go back, and fill the required fields!\n";
die();
}
// PREPARE THE DATA
$name = Trim(stripslashes($_POST[‘name’]));
//all the fields of the form here like the lines above, and below
$comment = Trim(stripslashes($_POST[‘comment’]));
// PREPARE EMAIL BODY TEXT
$body = ‘’;
$body .= “Dear " . $name . " " . $lastname . " thank you for your registration which will be finalized once payment of the fees has been confirmed (see fees & terms). \n
The following are the information you have provided. \n
Please kindly review them and in case of mistakes please contact this email. Do NOT register again.” . “\n \n”; // THIS IS TO HAVE PERSONALIZED MESSAGE
foreach ($clean_post as $key => $value) {
$body .= $key . ': ’ . $value . “\n”;
}
$submitter = $_POST[“email”];
$noreply = "[email protected]";
// send email
$success = mail($EmailTo, $Subject, $body, “From: <$EmailFrom>”);
mail($submitter, $Subject, $body, “From: <$noreply>”);
// redirect to success page
if ($success){
header( “Location: path/to/thankyou_reg.php” );
}
else
{print “There has been a technical problem, please resend, thank you.”; }
?>[/php]
Also, if I’m not asking too much is there a way to get the address of the sender, regardless of him/her filling the email field?
And is it possible to put html in the body message:
[php]$body .= “Dear " . $name . " " . $lastname . " thank you for your registration which will be finalized once payment of the fees has been confirmed (see fees & terms). \n
The following are the information you have provided. \n
Please kindly review them and in case of mistakes please contact this email. Do NOT register again.” . “\n \n”;[/php]
Thank you