Jump to content

Link in mail() not working


Blunketts dog

Recommended Posts

Hi there,

 

when i run this code:

<?php

 

$message = ' <html>

  <body>

  <p>Click <a href = "www.yahoo.com">here </a>for yahoo</p>

  </body>

</html>';

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: Me <Me@home.com>';

 

mail ('user@home.com', 'Test mail', $message, $headers);

 

?>

 

I am hoping to get an email that contains a link that I can click on to get to yahoo. What actually happens is i just get an email that says 'Click here to go to yahoo' but no clickable link.

 

Can anyone tell me what i am doing wrong?

 

Many thanks

Link to comment
Share on other sites

I treid this:

try using 'http://www.yahoo.com' not "www.yahoo.com" my server doesn't like it with "" only with '' in emails

and it worked fine. Many thanks

 

I will bear this

if what i suggested fails try changing your headers to

 

$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";

 

hope i have helped but on my server if i put "www.yahoo.com" it wouldn't work either has to be 'http://www.yahoo.com' for it to work on mine

and this

is your mamilbox blocking the link cause you aren't using enough headers to ID your email address you are sending from?

 

If it can phrase the html odds are that is the answer

in mind if I run into any problems.

 

Thanks for all your help - this is my first go at a php project and i thought i had fallen at the final hurdle!

Link to comment
Share on other sites

OK, I got that working but what i really want to do is use an address I have in a variable as so:

<?php

 

$link = "http://www.yahoo.co.uk"

 

$message = ' <html>

        <body>

        <p>Click <a href = $link>here </a>for yahoo</p>

        </body>

      </html>';

 

$headers  = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'From: Me <Me@home.com>';

 

mail ('user@home.com', 'Test mail', $message, $headers);

 

?>

but this gives me an email that says 'click for yahoo' with no clickable bit and no sign of either the address or the variable it has come from. Is there a way round this or have i overlooked something more obvious?

 

Thanks again

Link to comment
Share on other sites

You guys forgot to escape the ' inside

<?php
$link = "http://www.yahoo.co.uk";

$message = ' <html>
        <body>
        <p>Click <a href =\'$link\'>here </a>for yahoo</p>
        </body>
      </html>';

 

That just gives an email of 'click here for yahoo' with no hyperlink

 

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

 

 

You need to read about what type of quotes to use where

 

I had a look at it this but it didn't really help me. Its all a bit too complex for me to get my head round what I am doing and where i am going wrong

Link to comment
Share on other sites

Make sure you check that in outlook, thunderbird, hotmail, gmail and a cell phone or two - html emails are notoriously buggy. Each mail client renders them differently. I avoid them altogether - not worth the hassles.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.