dca_steve Posted July 20, 2012 Share Posted July 20, 2012 Hi all - I have a form where I'm gathering info from a drop-down list, and placing what the user selects into an array (the user can select more than one item from the drop-down). I then want to take the selections from the array, and put them into an email with line breaks between each item the user selected. This is working except the first 2 entries are always run together, with no line break. Here's a portion of what my generated email looks like: ****** If yes, please identify the Accrediting Agency: Accreditation Commission for Acupuncture and Oriental Medicine Accrediting Bureau of Health Education Schools American Podiatric Medical Association Council on Podiatric Medical Education ****** This should look like this instead: ***** If yes, please identify the Accrediting Agency: Accreditation Commission for Acupuncture and Oriental Medicine Accrediting Bureau of Health Education Schools American Podiatric Medical Association Council on Podiatric Medical Education ***** Not sure why the first 2 items are run together. Here is how I define the array: $accred_agency_form = implode("\r\n", $_POST['accred_agency']); And how it looks as far as being put into the body of the email: $body .= "If yes, please identify the Accrediting Agency:\n".$accred_agency_form." \n\n"; Any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/ Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Why are you using Windows line-breaks (\r\n) in your implode, but Unix line-breaks (\n) for the rest? Have you checked the raw output of $accred_agency_form? Perhaps the \r\n is there, but client-side behaviour is causing it to display improperly. I've never seen implode fail to insert a delimiter between array values. Perhaps you should also verify $_POST['accred_agency'] is structured the way you expect. Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363089 Share on other sites More sharing options...
dca_steve Posted July 20, 2012 Author Share Posted July 20, 2012 xyph - thanks for the quick reply. As far as using windows/UNIX breaks, I've been trying everything to solve this and that's what I've been using now. Earlier tried just \n and that wasn't working. Just did an echo $accred_agency_form; on the array and got this: Accreditation Commission for Acupuncture and Oriental Medicine Accrediting Bureau of Health Education Schools American Board of Funeral Service Education Committee on Accreditation Assume I should be seeing this instead.... Accreditation Commission for Acupuncture and Oriental Medicine Accrediting Bureau of Health Education Schools American Board of Funeral Service Education Committee on Accreditation Not sure what to do from here? Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363095 Share on other sites More sharing options...
dca_steve Posted July 20, 2012 Author Share Posted July 20, 2012 Just realized that it doesn't matter how many items I select from the drop down, it does put in a line break, but just one. So for instance if I select 3 items, it runs the first 2 together, then puts in a line break and correctly places the 3rd item next. If I select 6 items, it runs the first 5 together, puts in a break, then places the 6th item correctly, etc. It seems to think the only place a line break should be is immediately before the very last item selected. Not sure how to correct this.... Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363103 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 You're viewing the output in HTML, not plain text. View the source of the page, or output it surrounded by <pre> tags. echo "<pre>Raw output: ********* $accred_agency_form ********* Raw array dump:"; print_r($_POST['accred_agency']); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363105 Share on other sites More sharing options...
dca_steve Posted July 20, 2012 Author Share Posted July 20, 2012 xyph - you rock, thanks. So I did what you said and got this....looks good huh? Raw output: ********* Accreditation Commission for Acupuncture and Oriental Medicine Accreditation Commission for Midwifery Education Accrediting Bureau of Health Education Schools Accrediting Commission of Career Schools and Colleges ********* Raw array dump:Array ( [0] => Accreditation Commission for Acupuncture and Oriental Medicine [1] => Accreditation Commission for Midwifery Education [2] => Accrediting Bureau of Health Education Schools [3] => Accrediting Commission of Career Schools and Colleges ) So since it still looks incorrect in my email, the culprit may 'client-side behavior' you are talking about? Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363106 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Apparently. It seems to be displaying wonderfully in your browser. Have you tried checking the email with another client? Have you specifically declared the e-mail as text/plain in you email headers? Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363110 Share on other sites More sharing options...
dca_steve Posted July 20, 2012 Author Share Posted July 20, 2012 No to both of your questions....just added this: $header = "Content-type: text/plain; charset=iso-8859-1\r\n"; ...and that didn't help. Will continue to try different things! Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363117 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Send the email over to [email protected] I'll let you know if there's anything I can see wrong with the email itself. Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363119 Share on other sites More sharing options...
dca_steve Posted July 20, 2012 Author Share Posted July 20, 2012 Just sent it! Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363121 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Weird, it's sending the body in base64. Your mail server might be wonking this up :/ Can we see the entire script? It's odd that some fields are registering line-breaks properly. It's also very odd only the last line-break registers in the decoded email, when your source data has line-breaks between each option. Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363124 Share on other sites More sharing options...
dca_steve Posted July 20, 2012 Author Share Posted July 20, 2012 Here's the top part (btw gotta go to lunch will be back in an hour or so)...thanks for checking this out for me xyph, you've been a huge help! <?php //session_start(); require('captcha/captcha.php'); include('mysql_connect.php'); $captcha_passed = 0; $date_submitted = date('n/j/Y g:i:s A'); $report_year_form = addslashes($_POST['report_year']); $institution_name_form = addslashes($_POST['institution_name']); $institution_code_form = addslashes($_POST['institution_code']); $street_address_form = addslashes($_POST['street_address']); $city_form = addslashes($_POST['city']); $state_form = addslashes($_POST['state']); $zip_code_form = addslashes($_POST['zip_code']); $branch_locations_form = addslashes($_POST['branch_locations']); $satellite_locations_form = addslashes($_POST['satellite_locations']); $current_asmnts_form = addslashes($_POST['current_asmnts']); $disp_action_form = addslashes($_POST['disp_action']); $inst_recognized_form = addslashes($_POST['inst_recognized']); //$accred_agency_form = implode($_POST['accred_agency'],"\n"); $accred_agency_form = implode("\n", $_POST['accred_agency']); $accred_agency_form_db = implode(",",$_POST['accred_agency']); $accred_specialized_form = addslashes($_POST['accred_specialized']); $higher_aid_form = addslashes($_POST['higher_aid']); $veteran_ed_form = addslashes($_POST['veteran_ed']); $cal_aid_form = addslashes($_POST['cal_aid']); $add_fin_aid_form = addslashes($_POST['add_fin_aid']); $fin_aid_program_form = addslashes($_POST['fin_aid_program']); $doc_degrees_form = addslashes($_POST['doc_degrees']); $enroll_doctorate_form = addslashes($_POST['enroll_doctorate']); $mas_degrees_form = addslashes($_POST['mas_degrees']); $enroll_master_form = addslashes($_POST['enroll_master']); $bac_degrees_form = addslashes($_POST['bac_degrees']); $enroll_bachelor_form = addslashes($_POST['enroll_bachelor']); $asc_degrees_form = addslashes($_POST['asc_degrees']); $enroll_associate_form = addslashes($_POST['enroll_associate']); $dip_cert_form = addslashes($_POST['dip_cert']); $enroll_cert_form = addslashes($_POST['enroll_cert']); $inst_catalog_form = addslashes($_POST['inst_catalog']); $link_catalog_form = addslashes($_POST['link_catalog']); $user_email = $_REQUEST['user_email']; $accred_agency_form_array = explode(",",$accred_agency_form_db); if(isset($_POST['Submit2'])){ if($_SESSION['captchacode'] == $_POST['captcha']){ //set query $query= 'Insert into report_profile_dev Set date_submitted = "'.$date_submitted.'", ip_address = "'.$_SERVER['REMOTE_ADDR'].'", report_year = "'.$report_year_form.'", institution_name = "'.$institution_name_form.'", institution_code = "'.$institution_code_form.'", street_address = "'.$street_address_form.'", city = "'.$city_form.'", state = "'.$state_form.'", zip_code = "'.$zip_code_form.'", branch_locations = "'.$branch_locations_form.'", satellite_locations = "'.$satellite_locations_form.'", current_asmnts = "'.$current_asmnts_form.'", disp_action = "'.$disp_action_form.'", inst_recognized = "'.$inst_recognized_form.'", accred_agency = "'.$accred_agency_form.'", accred_specialized = "'.$accred_specialized_form.'", higher_aid = "'.$higher_aid_form.'", veteran_ed = "'.$veteran_ed_form.'", cal_aid = "'.$cal_aid_form.'", add_fin_aid = "'.$add_fin_aid_form.'", fin_aid_program = "'.$fin_aid_program_form.'", doc_degrees = "'.$doc_degrees_form.'", enroll_doctorate = "'.$enroll_doctorate_form.'", mas_degrees = "'.$mas_degrees_form.'", enroll_master = "'.$enroll_master_form.'", bac_degrees = "'.$bac_degrees_form.'", enroll_bachelor = "'.$enroll_bachelor_form.'", asc_degrees = "'.$asc_degrees_form.'", enroll_associate = "'.$enroll_associate_form.'", dip_cert = "'.$dip_cert_form.'", enroll_cert = "'.$enroll_cert_form.'", inst_catalog = "'.$inst_catalog_form.'", link_catalog = "'.$link_catalog_form.'"'; $result = mysql_query($query); echo "<pre>Raw output: ********* $accred_agency_form ********* Raw array dump:"; print_r($_POST['accred_agency']); echo "</pre>"; //echo $query; $to = $_POST['user_email']; $header = "From: Annual Report Institution Data <[email protected]>\r\n"; $header .= "Bcc: [email protected]\r\n"; $subject = "Annual Report Institution Data"; $body = "ANNUAL REPORT INSTITUTION DATA \n\n\n\n"; $body .= "Reporting Year: ".$report_year_form."\n\n"; $body .= "Institution Name: ".$institution_name_form."\n\n"; $body .= "Institution Code: ".$institution_code_form."\n\n"; $body .= "Street Address: ".$street_address_form."\n\n"; $body .= "City: ".$city_form."\n\n"; $body .= "State: ".$state_form."\n\n"; $body .= "ZIP Code: ".$zip_code_form."\n\n"; $body .= "Number of Branch Locations: ".$branch_locations_form."\n\n"; $body .= "Number of Satellite Locations: ".$satellite_locations_form."\n\n"; $body .= "Is this institution current with all assessments to the Student Tuition Recovery Fund?: ".$current_asmnts_form." \n\n"; $body .= "Is your institution approved by an accrediting agency recognized by the United States Department of Education? Please include only full institutional approval, not programmatic approval: ".$inst_recognized_form." \n\n"; $body .= "If yes, please identify the Accrediting Agency:\n ".$accred_agency_form." \n\n"; $body .= "If your institution has specialized accreditation from a recognized United States Department of Education approved specialized/programmatic accreditor, please list the accreditation: ".$accred_specialized_form." \n\n"; $body .= "Has any accreditation agency taken any formal disciplinary action against this institution?: ".$disp_action_form." \n\n"; $body .= "Does your institution participate in federal financial aid programs under Title IV of the Federal Higher Education Act?: ".$higher_aid_form." \n\n"; $body .= "Does your institution participate in federal veteran's financial aid education programs?: ".$veteran_ed_form." \n\n"; $body .= "Does your institution participate in California financial aid programs, such as the Cal Grant program?: ".$cal_aid_form." \n\n"; $body .= "Does your institution participate in, or offer any additional financial aid program?: ".$add_fin_aid_form." \n\n"; $body .= "Additional financial aid program: ".$fin_aid_program_form." \n\n"; $body .= "Number of Doctorate Degrees Offered: ".$doc_degrees_form." \n\n"; $body .= "Number of Students enrolled in Doctorate level programs at this Institution: ".$enroll_doctorate_form." \n\n"; $body .= "Number of Master Degrees Offered: ".$mas_degrees_form." \n\n"; $body .= "Number of Students enrolled in Master level programs at this institution: ".$enroll_master_form." \n\n"; $body .= "Number of Bachelor Degrees Offered: ".$bac_degrees_form." \n\n"; $body .= "Number of Students enrolled in Bachelor level programs at this institution: ".$enroll_bachelor_form." \n\n"; $body .= "Number of Associate Degrees Offered: ".$asc_degrees_form." \n\n"; $body .= "Number of Students enrolled in Associate level programs at this institution: ".$enroll_associate_form." \n\n"; $body .= "Number of Diploma or Certificate Programs Offered: ".$dip_cert_form." \n\n"; $body .= "Number of Students enrolled in Diploma or Certificate programs at this institution: ".$enroll_cert_form." \n\n"; $body .= "Link to your institutional catalog if it appears on your website: ".$inst_catalog_form." \n\n"; $body .= "Method by which you are providing your catalog: ".$link_catalog_form." \n\n"; mail($to, $subject, $body, $header); $captcha_passed = 1; session_destroy(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363128 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 This is very odd... Do the line-breaks show up properly in the database row? Seems like base64 doesn't mess up linebreaks <?php header('content-type: text/plain'); $test = array('one','two','three'); $implode = implode("\n",$test); echo $implode."\n\n"; $base64 = base64_encode($implode); echo $base64."\n\n"; $back = base64_decode($base64); echo $back; ?> output one two three b25lCnR3bwp0aHJlZQ== one two three What happens if you implode using a double line-break? "\n\n" Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363131 Share on other sites More sharing options...
dca_steve Posted July 20, 2012 Author Share Posted July 20, 2012 xyph - jackpot, sort of! The double line break resulted in this in my email: If yes, please identify the Accrediting Agency: Accreditation Commission for Acupuncture and Oriental Medicine Accreditation Commission for Midwifery Education Accrediting Bureau of Health Education Schools Accrediting Commission of Career Schools and Colleges Accrediting Council for Continuing Education and Training Soooo....that's better! Thanks - gonna still mess around with it to get rid of that extra space... Quote Link to comment https://forums.phpfreaks.com/topic/266008-line-breaks-and-arrays/#findComment-1363159 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.