Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP, mailto syntax

Posted on 2008-06-12
7
Medium Priority
?
1,772 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 19

Accepted Solution

by:
LordOfPorts earned 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 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