Solved

PHP, mailto syntax

Posted on 2008-06-12
7
1,760 Views
Last Modified: 2011-10-19
I am trying to add "body" to mailto function, how do I add two values in two differnt lines. Here's how I am trying to do it.


$body = "Title: ". $title. "<br />". "Date: ". $date. "<br />";

print "<a href='mailto:someone@microsoft.com?subject=Hello%20again&amp;body=$body'> e-mail</a>"; 
 

It just prints the output as it is aong with the break tags, any suggesions?

ty

Open in new window

0
Comment
Question by:martyje
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Expert Comment

by:psimation
Comment Utility
print "<a href='mailto:someone@microsoft.com?subject=Hello%20again&amp;body=$body'> e-mail</a>";
needs to be:
print "<a href='mailto:someone@microsoft.com?subject=Hello%20again&body=$body'> e-mail</a>";
0
 

Author Comment

by:martyje
Comment Utility
Still the same output: here's the output:
Title: Gymnast of the Week<br />Date: Mar 6 2008 <br />
0
 
LVL 17

Expert Comment

by:psimation
Comment Utility
Sorry, I cannot find any references on the net where you can send the content encoding via this method. I'm not sure it's possible to do this via a mailto: link. Using <br> in your body assumes that the e-mail client of the person clicking the link is set to HTML by default, but even if it is, I think you must explicitly send header information to the client to tell it to tell it to compile the message in HTML format. As it is, the client takes your body content "literaly" and does not attempt to "parse" the html.
 


0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 19

Accepted Solution

by:
LordOfPorts earned 125 total points
Comment Utility
You can accomplish the objective by using the ereg_replace function upon the body string by replacing each instance of <br />, <br>, and \n with %0A i.e.:

$body = ereg_replace("\n|<br />|<br>", "%0A", "Title: ". $title. "<br />". "Date: ". $date. "<br />");

The following tested successfully:


<?php
 

$title = "Test title.";

$date = "1900-01-01";
 

$body = ereg_replace("\n|<br />|<br>", "%0A", "Title: ". $title. "<br />". "Date: ". $date. "<br />");

print "<a href=\"mailto:someone@microsoft.com?subject=Hello%20again&amp;body=$body\"> e-mail</a>";
 

?>

Open in new window

EncodingNewLine.png
0
 

Author Closing Comment

by:martyje
Comment Utility
Awesome... thanks much; works great.
Just curious, what exactly that ereg_replace function is doing?
Thanks much
0
 
LVL 19

Expert Comment

by:LordOfPorts
Comment Utility
Thank you for the grade and the points! The ereg_replace function http://us3.php.net/manual/en/function.ereg-replace.php allows you to replace a pattern identified by a regular expression, with a specified value. In this case the pattern states replace any new line (\n) or <br /> or <br> tags with the encoded value for a new line %0A, this is e.g. like %20 for space. The e-mail client recognizes the encoded value for a new line and inserts it at the appropriate location in the message body.
0
 

Author Comment

by:martyje
Comment Utility
Thanks for the explaination :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now