[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-06-08
11
Medium Priority
?
310 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 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