how do I insert html (a href) into the contents of an email message

I have a function like this...

    require_once('Mail.php'); //---pear class
    $headers['From'] = $pFrom;
    $headers['To'] = $pTo;
    $headers['Subject'] = $pSubject;
    $params['host'] = '';

    $mail_object = & Mail::factory('smtp', $params);
    $mail_object->send($pTo, $headers, $pMessage);

I want to put a url in the message eg..

<a href='$setup->seStartingDirectory&report=$r&p=$p' target='_top'>
click here

but it displays it literally
All I want is..

click here

Who is Participating?
callrsConnect With a Mentor Commented:
Step 1:
In the value of $pMessage, be sure to enclose the entire message in opening <html>  and closing </html> tags

Step 2: Set the Content-type header
$headers['MIME-Version'] = '1.0';
$headers['Content-type'] = 'text/html; charset=iso-8859-1'

Hope it works. I based the above on Example 4 at
I think the mismatched < > pairs are causing the problem
<a .... > .... >

What if you replace the middle > with this: &#62;

Don't know much about email programs, but don't you have to set it to send as html and/or enclose the html part in <html>...</html> tags?
stevencopleyAuthor Commented:
I tried that but still shows all the html stuff.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

How about moving the part


up on a separate line first, without knowing php something like


(if that is the syntax to set a var to something)

and then the url line something like:
<a href='$tmpvar&report=$r&p=$p' target='_top'>


You've got a couple of issues here. First of all, if you need php to parse some variables you'll need to use " not '. Also, to make it easier to read, i'd use {} around the variables i.e.

<a href="{$setup->seStartingDirectory}&report={$r}&p={$p}" target="_top">
click here

Hope this helps
Just looking at your previous code, the following syntax is probably more suited:

$pMessage = "<a href='{$setup->seStartingDirectory}&report={$r}&p={$p}' target='_top'>click here</a>";

stevencopleyAuthor Commented:
Sorry everyone the html I want to put in an email is this...

<a href='' target='_top'>
click here

please don't get bogged down on the syntax.

Again sorry my sample was both wrong and dumb.

I want to end up with a link that just says

click here (underscored as a link to

I dont want to see any html code.
in other words, I want to email a link to someone.
and I dont know how to do it.
stevencopleyAuthor Commented:
Thanks for sticking in there with me..
Thanks for the A. And funny thing is, I've never used Pear or PHP before :O

I'm just an avid learner haha
To thank gotta be nice to the environment that feeds my soul  ;)

Since you got it going, try this experiment:  Place the <html>..</html> tags only around PART of the message.
What happens to the rest of the sent message then:  Does the  non-enclosed part appear without HTML formatting, or with?
Fan example say the message is the text below. If received as text, spacing is retained. Received as HTML, 3 lines would turn into 1 line without any <BR> or <P> statements.. So what actually appears? Thanks.
-->Start of message
<html>html part of message <a href='' target='_top'>click here</a><html>
line one of text part
line two
line three
<--end of message
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.