Solved

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

Posted on 2006-06-08
11
303 Views
Last Modified: 2006-11-18
I have a function like this...


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

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


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

<a href='www.bob.com/reportrun.php?x=1&sd=$setup->seStartingDirectory&report=$r&p=$p' target='_top'>
click here
</a>

but it displays it literally
All I want is..

click here

0
Comment
Question by:stevencopley
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 30

Expert Comment

by:callrs
ID: 16867725
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?
0
 

Author Comment

by:stevencopley
ID: 16867817
callrs,
I tried that but still shows all the html stuff.
0
 
LVL 30

Expert Comment

by:callrs
ID: 16867868
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 30

Expert Comment

by:callrs
ID: 16867876
0
 
LVL 2

Expert Comment

by:homemade
ID: 16873207
How about moving the part

$setup->seStartingDirectory

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

$tmpvar=$setup->seStartingDirectory

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

and then the url line something like:
<a href='www.bob.com/reportrun.php?x=1&sd=$tmpvar&report=$r&p=$p' target='_top'>


0
 
LVL 1

Expert Comment

by:beckw
ID: 16874376
Hello,

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="www.bob.com/reportrun.php?x=1&sd={$setup->seStartingDirectory}&report={$r}&p={$p}" target="_top">
click here
</a>

Hope this helps
0
 
LVL 1

Expert Comment

by:beckw
ID: 16874441
Just looking at your previous code, the following syntax is probably more suited:

$pMessage = "<a href='www.bob.com/reportrun.php?x=1&sd={$setup->seStartingDirectory}&report={$r}&p={$p}' target='_top'>click here</a>";

0
 

Author Comment

by:stevencopley
ID: 16882688
Sorry everyone the html I want to put in an email is this...

<a href='www.bob.com/report.php' target='_top'>
click here
</a>

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 www.bob.com/report.php)

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.
0
 
LVL 30

Accepted Solution

by:
callrs earned 500 total points
ID: 16884466
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 http://www.zend.com/manual/function.mail.php
0
 

Author Comment

by:stevencopley
ID: 16888940
callrs,
Thanks for sticking in there with me..
0
 
LVL 30

Expert Comment

by:callrs
ID: 16891131
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 me...you 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='www.bob.com/report.php' target='_top'>click here</a><html>
line one of text part
line two
line three
<--end of message
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

828 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