Bottyz Posted September 29, 2011 Share Posted September 29, 2011 Hi all, I'm currently rewriting our contact us form using the php Pear Mail package. It allows both html based emails and text based emails, and displays the relevant version based on the end recipients broswer capabilities. I have the html version working perfect, however the text based version spits out the whole message without line breaks. Since some of the computers in our building only except text emails (due to security) it needs to be laid out so that it is legible. I've searched around and tried various options but the emails are still arriving without breaks. So as an example: A User Inputs the following message using a textarea on the php form: Hi there, Great website, need help with such and such though. Regards Bob The email message gets collected and included in a html message. Then a duplicate text based message is made like so (Code so far): $plaintxt = '-----------------------------------------' . "\n"; $plaintxt .= Website Enquiry' . "\n"; $plaintxt .= '-----------------------------------------' . "\n"; $plaintxt .= 'A visitor to our website has submitted the following enquiry:' . "\n\n"; $plaintxt .= 'Name: ' . $visitor_name . "\n"; $plaintxt .= 'Company Name: ' . $visitor_companyname . "\n"; $plaintxt .= 'Email Address: ' . $visitor_email . "\n"; $plaintxt .= 'Telephone Number: ' . $message_telephone . "\n\n"; $plaintxt .= 'Subject of Enquiry: ' . $msg_subject . "\n"; $plaintxt .= 'Enquiry: ' . "\n\n"; $plaintxt .= $message_body . "\n\n"; $plaintxt .= '-----------------------------------------' . "\n\n"; $plaintxt .= 'User IP Address:' . $ip . "\n"; $plaintxt .= 'User Browser Info:' . $httpagent . "\n"; $plaintxt .= 'Date/Time Submitted:' . $time . "\n"; $crlf = "\n"; $headers = array('From' => $contact_from_email, 'Return-Path' => $contact_from, 'Subject' => $subject, 'To' => $contact_to); // Creating the Mime message $mime = new Mail_mime($crlf); // Setting the body of the email $mime->setTXTBody($htmlmessage); //Text version of the email $mime->setHTMLBody($plaintxt); // HTML version of the email "\n"; - These were suggested by users on the pear mail manual. Then once sent and opened you'd expect to see: ----------------------------------------- Website Enquiry ----------------------------------------- A visitor to our website has submitted the following enquiry: Name: Bob Company Name: Someplace Ltd Email Address: [email protected] Telephone Number: 01234 567890 Subject of Enquiry: help Enquiry: Hi there, Great website, need help with such and such though. Regards Bob ----------------------------------------- User IP Address: 123.456.789.012 User Browser Info: Mozilla Date/Time Submitted: 29th September 2011 09:56 However when opened in all the email applications I have (Outlook, Gmail, Live Mail, Hotmail, Yahoo) it looks like this: -----------------------------------------Website Enquiry-----------------------------------------A visitor to our website has submitted the following enquiry:Name: BobCompany Name: Someplace LtdEmail Address: [email protected] Number: 01234 567890Subject of Enquiry: helpEnquiry: Hi there,Great website, need help with such and such though.RegardsBob-----------------------------------------User IP Address: 123.456.789.012User Browser Info: MozillaDate/Time Submitted: 29th September 2011 09:56 Yet if you look at the source of the email. The line breaks are there. Am I missing something? Quote Link to comment https://forums.phpfreaks.com/topic/248091-inserting-line-breaks-into-text-based-email/ Share on other sites More sharing options...
Buddski Posted September 29, 2011 Share Posted September 29, 2011 Check the content type of the email you are sending. HTML should be sent as text/html Plain Text should be sent as text/plain Quote Link to comment https://forums.phpfreaks.com/topic/248091-inserting-line-breaks-into-text-based-email/#findComment-1273888 Share on other sites More sharing options...
Bottyz Posted September 29, 2011 Author Share Posted September 29, 2011 Check the content type of the email you are sending. HTML should be sent as text/html Plain Text should be sent as text/plain I've just looked at the message header of one of the text emails I've sent to my gmail and it does say text/plain: Content-Type: text/plain; charset=ISO-8859-1 Quote Link to comment https://forums.phpfreaks.com/topic/248091-inserting-line-breaks-into-text-based-email/#findComment-1273891 Share on other sites More sharing options...
xyph Posted September 29, 2011 Share Posted September 29, 2011 Try using "\r\n" I'm pretty sure the headers are supposed to be terminated with \r\n, so perhaps the client expects that in the body as well Quote Link to comment https://forums.phpfreaks.com/topic/248091-inserting-line-breaks-into-text-based-email/#findComment-1273930 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.