Solved

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

Posted on 2006-06-08
11
304 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
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.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

697 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