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 <[email protected]>';

 

mail ('[email protected]', '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
https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/
Share on other sites

It's probobally nothing to do with your code, but your email software is blocking the link incase it's spam.

 

Oh. Is there a way round this then. I have looked through my emails, and i have recieved some that contain links that work fine. How do they manage it?

 

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

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!

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 <[email protected]>';

 

mail ('[email protected]', '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

try this

 

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

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

 

that returns: Parse error: syntax error, unexpected T_VARIABLE

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.