Solved

PHP, mailto syntax

Posted on 2008-06-12
7
1,767 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Expert Comment

by:psimation
ID: 21773286
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
ID: 21773316
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
ID: 21773626
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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 
LVL 19

Accepted Solution

by:
LordOfPorts earned 125 total points
ID: 21786824
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
ID: 31466727
Awesome... thanks much; works great.
Just curious, what exactly that ereg_replace function is doing?
Thanks much
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 21794439
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
ID: 21794858
Thanks for the explaination :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

696 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