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:
$body .= "Dear " . $name . " " . $lastname . " thank you for your registration which will be finalized once payment of the fees has been confirmed (see fees & terms). \
The following are the information you have provided. \
Please kindly review them and in case of mistakes please contact this email. Do NOT register again." . "\
\
";
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:
foreach ($clean_post as $key => $value) {
$body .= $key . ': ' . $value . "\
";
}
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
//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 "<br/>$key is a required field\
";
$all_okay = FALSE;
}
}
// TEST FOR MISSING INPUT
if (!$all_okay) {
$referer = $_SERVER['HTTP_REFERER'];
echo "<br /><strong><a href=\\"$referer\\">Please click to go back, and fill the required fields!</a></strong>\
";
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). \
The following are the information you have provided. \
Please kindly review them and in case of mistakes please contact this email. Do NOT register again." . "\
\
"; // THIS IS TO HAVE PERSONALIZED MESSAGE
foreach ($clean_post as $key => $value) {
$body .= $key . ': ' . $value . "\
";
}
$submitter = $_POST["email"];
$noreply = "no-reply@site.com";
// 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."; }
?>
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:
$body .= "Dear " . $name . " " . $lastname . " thank you for your registration which will be finalized once payment of the fees has been confirmed (see fees & terms). \
The following are the information you have provided. \
Please kindly review them and in case of mistakes please contact this email. Do NOT register again." . "\
\
";
Thank you