Search code examples
phpplaintext

Line breaks in plain text email form


This is bound to be a simple one as my PHP skills are weak at best...

I have the following line which generates the email me sent for a job application, the email arrives correctly but there are no line breaks, it seems to print the \n (tried \r\n too)

$contact->setBodyMessageFields('Job Ref: [jobref] \n Vacancy Desc: [vacdesc] \n Full Name: [firstname] [lastname] \n Address: [address] \n Suburb: [suburb] \n Post Code: [postcode] \n Email: [mail] \n Phone: [phone] \n Mobile: [mobile] \n Message: [message] \n ');

So it's apparent that the \n within (' ') literally prints everything, I tried:

$contact->setBodyMessageFields('Job Ref: [jobref] '\n' Vacancy Desc:

But that seems to throw errors.

Any help would be greatly appreciated.

Please note: It unfortunately has to be plain text as another system pulls the data (and requires plain text).


Solution

  • You should replace the single quotes with double quotes:

    $contact->setBodyMessageFields("Job Ref: [jobref] \n Vacancy Desc: [vacdesc] \n Full Name: [firstname] [lastname] \n Address: [address] \n Suburb: [suburb] \n Post Code: [postcode] \n Email: [mail] \n Phone: [phone] \n Mobile: [mobile] \n Message: [message] \n ");
    

    See the PHP.net article on strings for more info.