Jump to content

Formatting email message in PHP


FredFogg

Recommended Posts

I am using php to send a text email and I am populating the message and I have tried a couple examples I found on the internet, but it isn't working. It is a simple email, so no need to send in html format. Here is what I have

 

$email_msg = 'Email : ' . $Email;

$email_msg .= '\n' .'First Name : ' . $FirstName;

$email_msg .= '\n' . 'Last Name : ' . $LastName;

 

and the email I am getting

 

Email : johnsmith@live.com\nFirst Name : john\nLast Name : smith

 

what I want is

 

Email : johnsmith@live.com

First Name : john

Last Name : smith

 

What am I doing wrong or do I need to add something to the header?

Link to comment
Share on other sites

$email_msg = 'Email : ' . $Email;
$email_msg .= "\n" .'First Name : ' . $FirstName;
$email_msg .= "\n" . 'Last Name : ' . $LastName;

 

' take the \n character literally. You need to encase it in double quotes.

Link to comment
Share on other sites

Ok, that fixed the formatting, but caused my variables not to print:

 

$email_msg = 'Email : ' . $Email;

$email_msg .= "\n" . 'First Name : ' . $FirstName;

$email_msg .= "\n" . 'Last Name : ' . $LastName;

 

results in:

 

Email :

First Name :

Last Name :

 

 

 

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.