chome4 Posted August 25, 2021 Share Posted August 25, 2021 I'm not a PHP programmer but have successfully used PHPMailer to set up a form that works by using pre-written code available out there. I've been asked to modify a contact form that has an extra empty 'CC' field. I can do that! But how can I make this blank field accept any email address so another person can be copied in. There doesn't seem to be any help, with examples. Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/313604-adding-code-to-enable-ccbcc-in-a-contact-form/ Share on other sites More sharing options...
requinix Posted August 26, 2021 Share Posted August 26, 2021 Would be nice to see some code... How will the code know what email address should be added in? Quote Link to comment https://forums.phpfreaks.com/topic/313604-adding-code-to-enable-ccbcc-in-a-contact-form/#findComment-1589374 Share on other sites More sharing options...
chome4 Posted August 26, 2021 Author Share Posted August 26, 2021 17 hours ago, requinix said: Would be nice to see some code... How will the code know what email address should be added in? Here is the code from a working contact form. I've seen "foreach ($mail_data['cc'] as $email => $name) { $driver->addCC($email, $name); }" ...but don't know anything about incorporating this into the code below. =============================================================================== <?php include 'phpmailer/class.phpmailer.php'; function GetIP(){ if(getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); }elseif(getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); if (strstr($ip, ',')) { $tmp = explode (',', $ip); $ip = trim($tmp[0]); } }else{ $ip = getenv("REMOTE_ADDR"); } return $ip; } $ip_adress = GetIP(); $name = addslashes(strip_tags($_POST['name'])); $sub = addslashes(strip_tags($_POST['subject'])); $email = addslashes(strip_tags($_POST['email'])); $message = addslashes(strip_tags($_POST['message'])); if(empty($name) || empty($email) || empty($message) || empty($sub)){header("Location:form.php?empty"); }else{ $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp.****.com"; // smtp host $mail->Port = "587"; //587 // Port $mail->SMTPAuth = true; $mail->Username = ******"; //mail address $mail->Password = "******"; //email password $mail->From = "******"; // from mail address $mail->Fromname = "no-reply"; // From Name $mail->AddAddress("*****","no name"); //your mail address and name $mail->WordWrap = 50; $mail->Subject = $sub; // Mail Subject $mail->Body = " Name : ".$name. " <br>E-mail: ".$email. " <br>Message: ".$message . " <br>IP : ".$ip_adress ; $mail->AddReplyTo($email,"Contact Form"); $mail->AddAddress('******'); //mail address $mail->IsHTML(true); if($mail->Send()) echo ""; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/313604-adding-code-to-enable-ccbcc-in-a-contact-form/#findComment-1589392 Share on other sites More sharing options...
requinix Posted August 26, 2021 Share Posted August 26, 2021 And what email address are you trying to add as CC? Or is it BCC? Quote Link to comment https://forums.phpfreaks.com/topic/313604-adding-code-to-enable-ccbcc-in-a-contact-form/#findComment-1589393 Share on other sites More sharing options...
chome4 Posted August 26, 2021 Author Share Posted August 26, 2021 36 minutes ago, requinix said: And what email address are you trying to add as CC? Or is it BCC? I want the form to have blank fields so the sender can optionally copy in others. Quote Link to comment https://forums.phpfreaks.com/topic/313604-adding-code-to-enable-ccbcc-in-a-contact-form/#findComment-1589395 Share on other sites More sharing options...
requinix Posted August 26, 2021 Share Posted August 26, 2021 Have you added those fields to the form yet? What does the HTML look like? Quote Link to comment https://forums.phpfreaks.com/topic/313604-adding-code-to-enable-ccbcc-in-a-contact-form/#findComment-1589396 Share on other sites More sharing options...
chome4 Posted August 26, 2021 Author Share Posted August 26, 2021 1 hour ago, requinix said: Have you added those fields to the form yet? What does the HTML look like? <form action="send.php" class="form-horizontal" id="contactForm" method="post" name="contactForm" style="width:100%"> <div class="form-group"> <label for="name">Name</label><br> <input id="name" name="name" type="text" placeholder="Your Name"> <span class="alert alert-danger e_name">*Name.</span> </div> <div class="form-group"> <label for="email">Email</label><br> <input id="email" name="email" type="email" placeholder="Your Email"> <span class="alert alert-danger e_email">*Email.</span> <span class="alert alert-danger e_email-1">*Email Validate !</span> </div> <div class="form-group"> <label for="email">CC</label><br> <input id="email" name="email" type="email" placeholder="CC (optional)"> <span class="alert alert-danger e_email">*Email.</span> <span class="alert alert-danger e_email-1">*Email Validate !</span> </div> <div class="form-group"> <label for="email">BCC</label><br> <input id="email" name="email" type="email" placeholder="BCC (optional)"> <span class="alert alert-danger e_email">*Email.</span> <span class="alert alert-danger e_email-1">*Email Validate !</span> </div> <div class="form-group"> <label for="subject">Subject</label><br> <input id="subject" name="subject" type="text" placeholder="Reason for Email"> <span class="alert alert-danger e_sub">*Subject.</span> </div> <div class="form-group"> <label for="subject">Message</label><br> <textarea class="textinput" cols="40" id="message" name="message" rows="10"></textarea> <span class="alert alert-danger e_mes">*Message.</span> </div> <div class="btn btn-info"> <a class="link" href="javascript:gonder();" id="btn">Send</a> </div> <div id="info"></div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/313604-adding-code-to-enable-ccbcc-in-a-contact-form/#findComment-1589397 Share on other sites More sharing options...
requinix Posted August 27, 2021 Share Posted August 27, 2021 See how all those new inputs are named "email"? That's not good. The name is how PHP knows which field's value to get so they all need to be different. Also the IDs, for that matter. IDs must be unique on a page. When those are fixed, post what you have (so we can see the new names) and then try adding some PHP code to get those values. It will be a couple lines that look very much like the lines to get the other fields' values. Give that a shot and post what you come up with so we can add them into the email message. Quote Link to comment https://forums.phpfreaks.com/topic/313604-adding-code-to-enable-ccbcc-in-a-contact-form/#findComment-1589400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.