stealthmode666 Posted December 25, 2008 Share Posted December 25, 2008 I keep coming back because I don't know enough about php and need help. My email I have requested as html email. I had to give up trying to use a table with TD/TR to display the data as the email is having issues sending the $body on $_POST The entire form fields have come through but the entire email body is one continious line. How would I make the script seperate each $field from my form? This is some of the code for the form fields. $fields = array(); $fields{"Member_Name"} = "Members Name"; $fields{"telephone"} = "Members Contact Phone Number"; $fields{"Email"} = "Members Email Address"; $fields{"Loan_Amount"} = "Loan_Amount £"; $fields{"title"} = "Main Applicants Title"; $fields{"surname"} = "Applicants Surname"; $fields{"forename"} = "Forename(s)"; $fields{"residential"} = "Residential Address"; $fields{"town"} = "Town"; $fields{"county"} = "County"; $fields{"postcode"} = "Postcode"; This is the $body part I use $body = "....You have received these contact details from form...:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } I also tried adding this but it sends all the $fields plus adds another load of the fields under the first lot, again as one continious line. #foreach($fields as $a => $b) #{ # $body .= "<tr><td>" . $a . "</td><td>" . $_REQUEST[$a] . "</td></tr>"; #} Thanks for looking and Merry Xmas to all Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/ Share on other sites More sharing options...
stealthmode666 Posted December 25, 2008 Author Share Posted December 25, 2008 How can it be so hard for me to simply send an email with all the form fields displayed in the body of the email, this is not new so how does everyone else do it? Am I missing something obvious here? been going in circles for weeks now and still not working right as to my email Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723677 Share on other sites More sharing options...
.josh Posted December 25, 2008 Share Posted December 25, 2008 try doing \r\n Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723680 Share on other sites More sharing options...
minidak03 Posted December 25, 2008 Share Posted December 25, 2008 Depending on your server sometimes \n and \r\n doesn't work, for some reason on my GoDaddy servers both the \n and \r\n won't work when I'm sending out my emails, try the following method if \n and \r\n doesn't work for you. (This method is not the best way to do it but it does work) $body = "....You have received these contact details from form...: "; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s ",$b,$_REQUEST[$a]); } I just placed in a hard return (hit enter to create a new line) which works for certain providers. Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723682 Share on other sites More sharing options...
stealthmode666 Posted December 25, 2008 Author Share Posted December 25, 2008 Thanks Crayon Violet, but that never worked, still the same, one continious line of an email,as in about 20 lines with no spaces or breaks, would take ages to type an email like this but i get it all in a split second :-\ I will now try MinidaK03's method. Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723686 Share on other sites More sharing options...
stealthmode666 Posted December 25, 2008 Author Share Posted December 25, 2008 Still no difference, still one continious line, I think it's since I added the html headers, i'll comment them out and see if any different Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723689 Share on other sites More sharing options...
kenrbnsn Posted December 25, 2008 Share Posted December 25, 2008 Please show us the code you're using to actually send the mail and the headers of the message. Ken Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723691 Share on other sites More sharing options...
minidak03 Posted December 25, 2008 Share Posted December 25, 2008 Something just like this usually works for me just fine (Thats when the \n or \r\n method does not work) <?php $to = "[email protected]"; $headers = "From: [email protected]"; $subject = "anything"; $message = "Line one This is now on the third line This is on the fourth line this is on the sixth line"; mail($to,$subject,$message,$headers); ?> But your right it may have something to do if your setting html headers Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723693 Share on other sites More sharing options...
stealthmode666 Posted December 25, 2008 Author Share Posted December 25, 2008 This is what I just done to see if any difference, and it sent me an email with all the fields now in one long list as a message and not as an html message. <?php $to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" ); $from = ( isset ($_REQUEST['Email']) ? $_REQUEST['Email'] : "default 'from' email goes here" ) ; $name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ; // I have commented out the headers below and used the one below this #$headers = # 'X-Mailer: PHP/' . phpversion() . "\r\n" . # "MIME-Version: 1.0\r\n" . # "Content-Type: text/html; charset=utf-8\r\n" . # "Content-Transfer-Encoding: 8bit\r\n\r\n"; // I used this instead, but now no html email $headers = "From: $from"; $subject = "Members Data From ......"; $fields = array(); $fields{"Member_Name"} = "Members Name"; $fields{"telephone"} = "Members Contact Phone Number"; $fields{"Email"} = "Members Email Address"; $fields{"Loan_Amount"} = "Loan_Amount £"; $fields{"title"} = "Main Applicants Title"; $fields{"surname"} = "Applicants Surname"; $fields{"forename"} = "Forename(s)"; $fields{"residential"} = "Residential Address"; $fields{"town"} = "Town"; $fields{"county"} = "County"; $fields{"postcode"} = "Postcode"; $fields{"years"} = "Lived At Address (Years)"; $fields{"months"} = "Lived At Address (Months)"; $fields{"hometelephone"} = "Home Tel No"; $fields{"mobile"} = "Mobile Tel No"; $fields{"dateofbirth"} = "D.O.B"; $fields{"nationality"} = "Nationality"; $fields{"sex"} = "Sex"; $fields{"marital"} = "Marital Status"; //Joint Applicant on ride side of form $fields{"title1"} = "2 Title"; $fields{"surname1"} = "2 Surname"; $fields{"forname1"} = "2 Forename(s)"; $fields{"residential1"} = "2 Residential Address"; $fields{"town1"} = "2 Town"; $fields{"county1"} = "2 County"; $fields{"post1"} = "2 Postcode"; $fields{"years1"} = "2 Years Lived at Address"; $fields{"months1"} = "2 Months"; $fields{"hometelephone1"} = "2 Home Telephone"; $fields{"mobile1"} = "2 Mobile Telephone"; $fields{"dateofbirth1"} = "2 D.O.B"; $fields{"nationality1"} = "2 Nationality"; $fields{"sex1"} = "2 Sex"; $fields{"marital1"} = "2 Marital Status"; $body = "You have received these contact details from .com:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: [email protected]"; $subject2 = "Thank-you for filling in the Form "; $autoreply = "Somebody from.. will get back to you as soon as possible, Thank-you"; if($from == '') {print "You have not entered an Email Address, please go back and try again";} else { if($name == '') {print "You have not entered a First Name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send){header( "Location: http://www......co.uk/r.../thankyou.html" );} else {print "We encountered an error sending your mail, please notify [email protected]"; } } } ?> This is the entire code. Also I don't need the if else statements but get errors when i remove them. I have .js server-side validation on every field on the form before it will submit to the php script. Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723696 Share on other sites More sharing options...
9three Posted December 25, 2008 Share Posted December 25, 2008 The company I work for is hosted under godaddy (this host sucks btw) and I am able to use space as my separation of lines or \r I just noticed youre trying \n try \r instead off topic: I had to call tech support and ask if they run under "localhost" or an IP address per database and the "tech support rep" asked me "whats localhost?"....sigh. Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723697 Share on other sites More sharing options...
stealthmode666 Posted December 25, 2008 Author Share Posted December 25, 2008 got two seperate hosts, two different companies, like I say now I have removed the html headers, I get a long list of all the fields in the array, I will settle for a way of making the $body of these divide into two columns with rows underneath each coloumn. I spent weeks on this and am going round in circles and no further ahead than when I started out. Would you know how to help me format the body tag to display the fields in columns or formatted rows? Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723701 Share on other sites More sharing options...
stealthmode666 Posted December 25, 2008 Author Share Posted December 25, 2008 I'm on my own again with this problem I guess, thanks anyway for having a look all. Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723707 Share on other sites More sharing options...
chronister Posted December 26, 2008 Share Posted December 26, 2008 Take a look at PHPMailer http://phpmailer.codeworxtech.com/. It takes a lot of headache out of sending multi-part messages, attachments and the like. I won't manually write mail scripts again. Nate Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-723877 Share on other sites More sharing options...
stealthmode666 Posted December 27, 2008 Author Share Posted December 27, 2008 Thanks chronister. Looking and trying now, problem is my form took about 2 days to design, make and impliment. been making forms for years and always used .js to check the validation, client and server-side. Collecting or sending the data on a form was never my problem, PHP was always done by others. And what a learning curve, but I will not give up till I learn and understand some of it. I have gone back to the html version of my script with the email containing the form fields in a table. But it only sends a certain amount of the table data and disregards the script after a certain line. Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-724228 Share on other sites More sharing options...
chronister Posted December 27, 2008 Share Posted December 27, 2008 I think I asked you in another topic about this. Does it stop "reading" after a particular point? Is that point the same everytime? Nate Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-724295 Share on other sites More sharing options...
stealthmode666 Posted January 3, 2009 Author Share Posted January 3, 2009 I think I asked you in another topic about this. Does it stop "reading" after a particular point? Is that point the same everytime? Yes chronister, my script stops reading after a certain line. It actually gets half way through reading/processing the line and sends the email with all fields formatted and doesn't get past a certain point in the script line. Also I have started trying to use the PHPMailer but not having much luck with it for what I'm trying to do. Can you shed any light on why a script will stop been read on processing? Quote Link to comment https://forums.phpfreaks.com/topic/138407-body-of-email-is-one-long-line/#findComment-728825 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.