Jump to content

Line breaks in Emails


Mateobus

Recommended Posts

I want to send a dynamic email, the only problem that I am having is that the line breaks won't work? Does anyone know how to put a line break in an email body? Here is my code:

$email = "someone@somewhere.com";
$subject = "Hey";
$body = "Dear Person,\nHow are you?";
echo "<a href=\"mailto:$email?subject=$subject&body=$body\">";

Everything is working except my email client isn't recognizing the line break (\n). I tried html (<br />) as well and that didn't work. Any help is appreciated.
Link to comment
Share on other sites

Ken,
I tried that with no success. Here is the problem, since the string is enclosed by double quotes, it is interpreting the line breaks and carriage returns before it ever gets to the email client.  So I think I want literal characters (single quotes) to be sent to the email client. This still doesn't work though because it shows up as \n in my email client.  Thank you for your help.

Matt
Link to comment
Share on other sites

While the above should work no matter what app you are using to write code ... I have seen in some IDE 's where the IDE will insert it's own type of line break in your code.

Then it gets passed in your script without your knowledge.  The way you can test this is; open the script in your IDE and just put some IDE line spacing where you would want the line break.  If it works then you know what/where you problem is.

To fix it you'll need a different IDE or find the option in your IDE to turn off the auto line spacing.

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.