Solved

PHP, mailto syntax

Posted on 2008-06-12
7
1,764 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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…

820 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