Jump to content

Inserting line breaks into text based email


Bottyz

Recommended Posts

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: bob@someplace.com

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: bob@someplace.comTelephone 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?

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.