jimmyt1988 Posted October 2, 2009 Share Posted October 2, 2009 hi all, I need the php mailer to email all the choices selected in my checkboxes. this is the html code: <tr width = "680px"> <td width = "33%" colspan = "2"> <h5 style = "margin:10px 0px 10px 0px;">Business groups</h5> </td> <td width = "33%" colspan = "2"> <h5 style = "margin:10px 0px 10px 0px;"> Private Groups</h5> </td> <td width = "33%" colspan = "2"> <h5 style = "margin:10px 0px 10px 0px;"> Healthcare</h5> </td> </tr> <tr width = "680px"> <td width = "250px"> - Business & Commercial </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Business and Commercial" tabindex="5" /> </td> <td width = "250px"> - Dispute Resolution </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Dispute Resolution" tabindex="6" /> </td> <td width = "250px"> - Care Providers </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Care Providers" tabindex="16" /> </td> </tr> <tr width = "680px"> <td width = "250px"> - Buying & Selling businesses </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Buying and Selling businesses" tabindex="7" /> </td> <td width = "250px"> - Employment </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Employment" tabindex="8" /> </td> <td width = "250px"> - Dentists </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Dentists" tabindex="16" /> </td> </tr> <tr width = "680px"> <td width = "250px"> - Commercial Property </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Commercial Property" tabindex="9" /> </td> <td width = "250px"> - Family </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Family" tabindex="10" /> </td> <td width = "250px"> - Doctors </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Doctors" tabindex="16" /> </td> </tr> <tr width = "680px"> <td width = "250px"> - Dispute Resolution </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Dispute Resolution" tabindex="11" /> </td> <td width = "250px"> - Mediation </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Mediation" tabindex="12" /> </td> <td width = "250px"> - Garden Centres </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Garden Centres" tabindex="16" /> </td> </tr> <tr width = "680px"> <td width = "250px"> - Employment </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Employment" tabindex="13" /> </td> <td width = "250px"> - Residential Property </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Residential Property" tabindex="14" /> </td> <td width = "250px"> - Vets </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Vets" tabindex="16" /> </td> </tr> <tr width = "680px"> <td width = "250px"> - Mediation </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Mediation" tabindex="15" /> </td> <td width = "250px"> - Will, Tax & Trusts </td> <td width = "50px"> <input style = "width:auto; border:0px;" type="checkbox" name="options[]" value="Will, Tax and Trusts" tabindex="16" /> </td> <td width = "250px"> </td> <td width = "50px"> </td> </tr> and here is the php mailer code which I'm obviously stuck on: $name = $_POST["name"]; $company = $_POST["company"]; $email = $_POST["email"]; $telephone = $_POST["telephone"]; $options = $_POST["options"]; $selection = count($options); for ($i = 0; $i < $selection; $i++){ echo ($options[$i] . " "); } $enquiry = $_POST["enquiry"]; $success_sent_msg='<p align="center"><strong> </strong></p> <p align="center"><strong>Your message has been successfully sent to us<br> </strong> and we will reply as soon as possible.</p> <p align="center">A copy of your query has been sent to you.</p> <p align="center">Thank you for contacting us.</p>'; $replymessage = "Hi $name Thank you for your email. We will endeavour to reply to you shortly. Please DO NOT reply to this email. Below is a copy of the message you submitted: -------------------------------------------------- Name: $name Company: $company Email: $email Telephone Number: $telephone Chosen Areas: $options Enquiry: $enquiry -------------------------------------------------- Thank you"; $themessage = "Name: $name \nCompany: $company \nEmail: $email \nTelephone Number: $telephone \nChosen Areas: $options \nEnquiry: $enquiry"; mail("$replyemail", "$thesubject", "$themessage", "From: $email\nReply-To: $email"); mail("$email", "Receipt: $thesubject", "$replymessage", "From: $replyemail\nReply-To: $replyemail"); echo $success_sent_msg; I understand the concept behind what I need to do but I don't have the experience to make it happen. any help, I been struggling for 4 hours now. I'm now trying this: but it returns ARRAY instead of the content within the array. $options = $_POST["options"]; $N = count($options); for ($i = 0; $i < $N; $i++){ $selection[] = ($options[$i] . " "); echo $selection; } Link to comment https://forums.phpfreaks.com/topic/176286-solved-php-mailer-checkboxes/ Share on other sites More sharing options...
cags Posted October 2, 2009 Share Posted October 2, 2009 I think what your after is something like this... <?php $chosen_areas = ''; $selection = count($options); for ($i = 0; $i < $selection; $i++){ $chosen_areas .= $options[$i] . "\r\n"; } $replymessage = "Hi $name Thank you for your email. We will endeavour to reply to you shortly. Please DO NOT reply to this email. Below is a copy of the message you submitted: -------------------------------------------------- Name: $name Company: $company Email: $email Telephone Number: $telephone Chosen Areas: $chosen_areas Enquiry: $enquiry -------------------------------------------------- Thank you"; ?> Link to comment https://forums.phpfreaks.com/topic/176286-solved-php-mailer-checkboxes/#findComment-929064 Share on other sites More sharing options...
jimmyt1988 Posted October 2, 2009 Author Share Posted October 2, 2009 Agh It doesn't work. any more thoughts? It's now returning the first letter of the last option chosen. <?php $name = $_POST["name"]; $company = $_POST["company"]; $email = $_POST["email"]; $telephone = $_POST["telephone"]; $options = $_POST["options"]; $selection = count($options); for ($i = 0; $i < $selection; $i++){ $chosenAreas = ($options[$i] . "\r\n"); } $enquiry = $_POST["enquiry"]; $success_sent_msg='<p align="center"><strong> </strong></p> <p align="center"><strong>Your message has been successfully sent to us<br> </strong> and we will reply as soon as possible.</p> <p align="center">A copy of your query has been sent to you.</p> <p align="center">Thank you for contacting us.</p>'; $replymessage = "Hi $name Thank you for your email. We will endeavour to reply to you shortly. Please DO NOT reply to this email. Below is a copy of the message you submitted: -------------------------------------------------- Name: $name Company: $company Email: $email Telephone Number: $telephone Chosen Areas: $chosenAreas Enquiry: $enquiry ?> Link to comment https://forums.phpfreaks.com/topic/176286-solved-php-mailer-checkboxes/#findComment-929071 Share on other sites More sharing options...
jimmyt1988 Posted October 2, 2009 Author Share Posted October 2, 2009 I think I understand what is happening.. The selection is placed into $chosenAreas.. but is then replaced by the second selection on the for loop. How do I make sure instead of replacing $chosenAreas with the new option it loops round, It adds it to the last piece of data added to $chosenAreas thus giving me an array of results instead of the last result it's overwriting the variable with. *cries* Link to comment https://forums.phpfreaks.com/topic/176286-solved-php-mailer-checkboxes/#findComment-929083 Share on other sites More sharing options...
cags Posted October 2, 2009 Share Posted October 2, 2009 I must admit I just re-used some of your code somewhat. Try this freshly written approach, I tested it, it should work with your form... <?php $chosenAreas = ''; if(isset($_POST['options'])) { foreach($_POST['options'] as $area) { $chosenAreas .= $area . "\r\n"; } } ?> Basically it should loop through the values returned from the form, adding them to the string $chosenAreas. The \r\n creates a new line, just incase you were unsure. EDIT: In reply to you last message, I've just realised the first option doesn't work because you removed the fullstop before the equals sign. The .= means concatinate, i.e, attach this variable to the end of the current value. Link to comment https://forums.phpfreaks.com/topic/176286-solved-php-mailer-checkboxes/#findComment-929086 Share on other sites More sharing options...
jimmyt1988 Posted October 2, 2009 Author Share Posted October 2, 2009 <?php $name = $_POST["name"]; $company = $_POST["company"]; $email = $_POST["email"]; $telephone = $_POST["telephone"]; $chosenAreas = ''; if(isset ($_POST["options"])){ foreach($_POST['options'] as $area){ $chosenAreas .= $area . "\r\n"; } } $enquiry = $_POST["enquiry"]; $success_sent_msg='<p align="center"><strong> </strong></p> <p align="center"><strong>Your message has been successfully sent to us<br> </strong> and we will reply as soon as possible.</p> <p align="center">A copy of your query has been sent to you.</p> <p align="center">Thank you for contacting us.</p>'; $replymessage = "Hi $name Thank you for your email. We will endeavour to reply to you shortly. Please DO NOT reply to this email. Below is a copy of the message you submitted: -------------------------------------------------- Name: $name Company: $company Email: $email Telephone Number: $telephone Chosen Areas: $chosenAreas Enquiry: $enquiry ?> I must be stupid because I still can't get it to work. Now it does not return anything *cries more* P.S I tried the first time with .= and it hadn't worked and I jsut copied the last thing I did in which was trying without. Thanks for the lesson on .= I didnt know:D Link to comment https://forums.phpfreaks.com/topic/176286-solved-php-mailer-checkboxes/#findComment-929096 Share on other sites More sharing options...
jimmyt1988 Posted October 2, 2009 Author Share Posted October 2, 2009 YEHAAA I GOT IT TO WORK. I GOT IT TO WORK... PARTTEEHHHHHHHHHHH Link to comment https://forums.phpfreaks.com/topic/176286-solved-php-mailer-checkboxes/#findComment-929107 Share on other sites More sharing options...
cags Posted October 2, 2009 Share Posted October 2, 2009 Whoop, whoop, lol, I was just about to post my full test code for you. EDIT: Btw, don't forget to set the topic to SOLVED (bottom left of screen) if it's done. Link to comment https://forums.phpfreaks.com/topic/176286-solved-php-mailer-checkboxes/#findComment-929109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.