Solved

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

Posted on 2006-06-08
11
300 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
Comment Utility
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
Comment Utility
callrs,
I tried that but still shows all the html stuff.
0
 
LVL 30

Expert Comment

by:callrs
Comment Utility
0
 
LVL 30

Expert Comment

by:callrs
Comment Utility
0
 
LVL 2

Expert Comment

by:homemade
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:beckw
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
callrs,
Thanks for sticking in there with me..
0
 
LVL 30

Expert Comment

by:callrs
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
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…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now