I have this form where I wan't people to sign up for receiving free stuff campaign. The form works fine and its send the details to the requested eMail. Now this form should also write the details to a csv file that we can handle the data more easily.
I use this form: $value) { ${"".$key} = $value; }
if (!isset($email)) {
header( "Location: $formurl" );
exit;
}
if ($_POST['services']) {
foreach($_POST['services'] as $value) {
$check_msg .= "- $value
";
}
}
function is_email($email) {
return ereg("^[^@ ]+@[^@]+\.[^@ ]+$", $email);
}
function validate_email($email) {
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("@",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}
return $valid;
}
$formurl = "/sticker/index.php" ;
$errorurl1 = "/sticker/error.php" ;
$errorurl2 = "/sticker/error.php" ;
$thankyouurl = "/sticker/success.php#start" ;
$http_referrer = getenv( "HTTP_REFERER" );
// get POST && GET vars to run with 'register_globals off'
//foreach($_GET AS $key => $value) {
// ${"".$key} = $value;
//}
$messageproper =
"============================================================
" .
"Sticker Request $firstname $lastname
" .
"============================================================
" .
"KUNDENDATEN
" .
"Vorname: $firstname
" .
"Nachname: $lastname
" .
"Firma: $company
" .
"Strasse: $street
" .
"Strasse2: $street2
" .
"PLZ: $zip
" .
"City: $city
" .
"Land: $country
" .
"Telefon: $phone
" .
"eMail: $email
" .
"Facebook Name: $fbname
" .
"--------------------------------------
" .
"Bemerkung: $comment
" .
"============================================================
" ;
$myFile = "/sticker/sticker.txt";
$fh = fopen($myFile, 'a');
$stringData = "
";
$x=0;
foreach($_POST AS $key => $value) {
$x!=0?$stringData=",".$stringData:'';
$stringData='"'.$firstname.'";"'.$lastname.'";"'.$company.'";"'.$street.'";"'.$street2.'";"'.$zip.'";"'.$city.'";"'.$country.'";"'.$phone.'";"'.$email.'";"'.$fbname.'";"'.$comment.'"'."
";
$x++;
}
fwrite($fh, $stringData);
fclose($fh);
$mailto = 'email@domain.com' ;
$subject = "Free Sticker Campaign: $company - $firstname $lastname";
mail($mailto, $subject, $messageproper, "From: \"$firstname $lastname\" <$email>
Reply-To: \"$lastname\" <$email>
X-Mailer: chfeedback.php 2.01" );
header( "Location: $thankyouurl" );
exit;
?>
As I said nothing gets written to the CSV File I declared in $myFile. Would be great if someone could let me know what to do. Thanks.