Hello Guys,I am creating one simple php form all works great but I want solution for one thing.I want cc optional like I have checkbox in the form & if user click it then only it should send CC mail other wise not.Here is the code which I am using. <?php ob_start(); $fromemail="No-Reply <demo@demo.com>"; // change here if you want $toemail="demo@demo.com"; // change here if you want $sub="Online Feedback"; // change here if you want $success_page_name="index.php"; ////// do not change in following if($_SERVER['REQUEST_METHOD']=="POST") { $fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1'])); $fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2'])); $contentmsg=stripslashes("<br><b><font style=color:#CC3300>$sub</font></b><br> <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Name :</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_1</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Email :</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_2</td> </tr> </table> "); //// $headers = "MIME-Version: 1.0 "; $headers .= "Content-type: text/html; charset=iso-8859-1 "; $from=$fromemail; $headers .= "From: ".$from." "; $headers.= "Cc: ".$fieldnm_2." "; @mail($toemail,$sub,$contentmsg,$headers); header("Location:$success_page_name"); } ?> PHP: Thanks in Advance!
I think you need something like : // at the FORM : ?> <input type="checkbox" name="send_cc" value="1" />Send a copy // add a checkbox <? // at your POST page : $send_cc = $_POST['send_cc']; if ($send_cc == 1) { $headers.= "Cc: ".$fieldnm_2; } // if the checkbox was checked, add a cc field to the mail headers PHP: good luck...
Thanks for solution,but I don't know how to write & where to write the following code.Please write & show me. $send_cc = $_POST['send_cc']; if ($send_cc == 1) { $headers.= "Cc: ".$fieldnm_2; } // Thanks For your Valuable Help!
You can add the line $send_cc = $_POST['send_cc']; PHP: Just below your lines : $fieldnm_1=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_1'])); $fieldnm_2=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['fieldnm_2'])); PHP: And you can add the lines : if ($send_cc == 1) { $headers.= "Cc: ".$fieldnm_2; } PHP: Below your line : $headers .= "From: ".$from; PHP:
Thank You! So Much.It works Great as I want.Can you tell me 1 more thing is it possible to send only selected details to user once form submitted. Thanks For HELP!
I'm afraid I don't understand your question... Can you be please more specific? Which details do you mean? You can send whatever you want via a form (with method POST) and then propagate at the post page...
Sorry,I mean I have a form which have 3 fields 1.Name 2.Email 3.Contact so when user submit it then he will get details with CC function but he should get only 2 details name & contact through CC. Hope you Understand. Thanks!
If you send an email (To) and a copy to someone else (Cc) you can't filter what to send to one and s'thing else to another. Both will see the SAME content. If that's what you asked...
Yes, you can send an email with those limited data. You'll have to create separate message body and call the mail() function twice. S'thing like: $contentmsg_1 = stripslashes("<br><b><font style=color:#CC3300>$sub</font></b><br> <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Name :</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_1</td> </tr> <tr> <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Email :</b> </td> <td width=565 align=left valign=top bgcolor=#FFFFFF>$fieldnm_2</td> </tr> </table> "); $contentmsg_2 =stripslashes("WHAT DO YOU WANT TO PASS TO THE VISITOR"); //// $headers = "MIME-Version: 1.0"; $headers .= "Content-type: text/html; charset=iso-8859-1"; $from=$fromemail; $headers .= "From: ".$from; if ($send_cc == 1) { @mail($toemail,$sub,$contentmsg_2,$headers); } @mail($toemail,$sub,$contentmsg,$headers); header("Location:$success_page_name"); PHP: Hope you'll get the idea...
Without any additional code: You send an email to the user with name and contact in the $message variable. Then send an email to you, using $message .= $email, so you get all 3.