[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP, mailto syntax

Posted on 2008-06-12
7
Medium Priority
?
1,774 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
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
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!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
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 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
Course of the Month18 days, 11 hours left to enroll

834 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