Adding HTML links in an array

Hi folks,

I have a unique problem where I need to create an array of links i.e.
Page 1
Page 2

and be able to add them to a big concatinated string that will be sent at the bottom of an e-mail such that the e-mail will show up displaying those links amongst other text.

I have the following code:
$promoItems = array(“Item1”, “Item2”, “Item3”, “Item4”, “Item5”);
foreach ($promoItems as $promoValues)
{
$emailstring .= "- " . $promoValues . “n”;
}

This works just fine, but I need those items to be linked to another page.
Is this even possible?
Any help would be greatly appreciated,

  • Michael

[php]$emailstring .= " - <a href="".$promoValues."">".$promoValues."";
[/php]

This perhaps?

Hi Zyppora,
Thank you for your reply.
Unfortunately, that solution displays the entire string of:
A Page
where I only want to display ‘A Page’
Thanks again and for any future help,

  • Michael

That sounds like HTML is disabled in your receiving email application (that, or the mimetype is not set correctly).

The weird thing is that the html file name i.e. http://www.somepage.com still shows up as a link but the text inside the link tags doesn’t.

Have you checked your quotes or tried escaping them?

example = (" A Page ");

-Teh Riddler

[php]
$emailstring .= " - <a href="".$promoValues."">".$promoValues."";
[/php]

The quotes were escaped :wink:

@MShaw087:
Sounds like your mimetype is incorrect (it’s probably text/plain when it should be text/html … or somethin like that).

Hi again,

I checked my e-mail outlook program and it is set to compose messages in html, not plain text. So I don’t think it’s a problem directly with the e-mail program. Could it be soemthing else?
Thanks again,

  • Michael

No, I’m talking about the headers of the email being sent through PHP, not the email program you’re using to receive them.

Thanks for your help. But this leads me to a somewhat unrelated problem.

I have stuck the links and text in seperate arrays and use the following code:

$somelinks = array(“Link 1”, “Link 2”);
$sometext = array(“Text 1”, “Text 2”);
for ($acounter = 0; $acounter < count($sometext); $acounter++)
{
$value1 = $somelinks[$acounter];
$value2 = $sometext[$acounter];
$emailstring .= " - <a href="".$value1."">".$value2.“n”
}

When I click the button to e-mail someone, the browser tries to load the page, but is unable to.
Assuming the arrays $somelinks and $sometext will always have the same number of items, is there anything in the code that should be causing this error?

Sounds like a timeout -> sounds like an infinite loop.

And the only thing I could think of causing your infinite loop is the following:

[php]$sometext = (“Text 1”, “Text 2”);[/php]

Arrays are instantiated like this:

[php]$sometext = array(“Text 1”, “Text 2”);[/php]

Sorry, I forgot to add that to my post. No, I actually have that correct in my program, so it’s something else causing the error.

  • Michael

Do you have any other loops in your script? Or recursive functions perhaps?

Hi again,

I don’t have any other loops or recursive functions. What’s weird is the e-mail button works and doesn’t time out if I were to remove the links and just have the text sent in the e-mail. It’s only when I add the links that the problem is caused.
Thanks again,

  • Michael

I also see you using this:

[php]for (acounter = 0; acounter < count($sometext); acounter++) [/php]

Shouldn’t that be:

[php]for ($acounter = 0; $acounter < count($sometext); $acounter++) [/php]

And if the problem only occurs when you add the links, then the problem is probably in there.

Hi Zyppora,

I think I was in such a rush when I added that post that I made more errors in it than in the actual code itself. Sorry, the actual code is as you have there (i’ll edit my post). Yes, it’s definetly the links. I know that for sure. Just to add more confusion, when testing out the links last week, the browser never timed our when I hit the e-mail button. It only started this week.
Thanks again,

  • Michael

You could try and trace back the bug using Debugging. Better make sure your variables contain what you expect them to contain :wink:

Hi again,

That problem seems to have just sorted itself out. Don’t ask me why it just started working again. I’m still unable to get the links to show up. How do I set up the e-mail so it reads html rather than text. I set the TextOnly property of the mail variable to false. Is there anything else I need to do?

  • Michael

Zyppora can correct if I am wrong, but you will want something similar to below for the headers:

[php]<?
$headers = “From: [email protected] rn”;
$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "MIME-Version: 1.0 ";
?>[/php]

Hi again,

I am using a PHPMailer object to sned the mail. How do I go about setting the header in the way you specified?

  • Michael
Sponsor our Newsletter | Privacy Policy | Terms of Service