html - send only field boxes filled. if empty then do not send in email. php form to email -
i have simple form email in php. nice thing form in send php code not have write out fields name.for example, not have write this:
$msg .= "$_post[contactname] contact name: contactname\n"
in code, have write is:
foreach ($_post $field=>$value) { $body .= "$field: $value\n";
the form working perfectly. sending this:
contactname: name here businessname: business name here emailaddress: email@email.com email_confirmation: phonenumber: 714-555-5555
however, wish happen: if field left empty or web user not fill field box, form should not send field. example: web user decides not fill in contactname , or businessname. form should send format:
emailaddress: email@email.com email_confirmation: phonenumber: 714-555-5555
noticed no mention of contactname: , businessname:
please help! appreciate it. -michelle ha.
here php send code:
if email_confirmation field empty if(isset($_post['email_confirmation']) && $_post['email_confirmation'] == ''){ // put email address here $youremail = 'bomandty@gmail.com'; // prepare "pretty" version of message $body .= "thank request. soon."; $body .= "\n"; $body .= "\n"; foreach ($_post $field=>$value) { $body .= "$field: $value\n"; $body .= "\n"; } $ccuser = $_post['emailaddress']; // use submitters email if supplied 1 // (and isn't trying hack form). // otherwise send email address. if( $_post['emailaddress'] && !preg_match( "/[\r\n]/", $_post['emailaddress']) ) { $headers = "from: $_post[emailaddress]"; } else { $headers = "from: $youremail"; } // finally, send message mail($youremail, 'subject line here', $body, $headers, $ccuser ); } // otherwise, let spammer think got message through
foreach ($_post $field=>$value) { if($value != ''){ $body .= "$field: $value\n"; } }
Comments
Post a Comment