Blunketts dog Posted February 28, 2009 Share Posted February 28, 2009 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 More sharing options...
only one Posted February 28, 2009 Share Posted February 28, 2009 It's probobally nothing to do with your code, but your email software is blocking the link incase it's spam. Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773168 Share on other sites More sharing options...
Blunketts dog Posted February 28, 2009 Author Share Posted February 28, 2009 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? Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773180 Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 try using 'http://www.yahoo.com' not "www.yahoo.com" my server doesn't like it with "" only with '' in emails Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773207 Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 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 Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773213 Share on other sites More sharing options...
cooldude832 Posted February 28, 2009 Share Posted February 28, 2009 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 Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773224 Share on other sites More sharing options...
Blunketts dog Posted February 28, 2009 Author Share Posted February 28, 2009 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 https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773231 Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 ok no problem you are welcome please mark this topic as solved Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773233 Share on other sites More sharing options...
Blunketts dog Posted February 28, 2009 Author Share Posted February 28, 2009 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 Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773356 Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 try this $link = "http://www.yahoo.co.uk"; $message = ' <html> <body> <p>Click <a href ='$link'>here </a>for yahoo</p> </body> </html>'; Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773363 Share on other sites More sharing options...
Blunketts dog Posted February 28, 2009 Author Share Posted February 28, 2009 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 Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773365 Share on other sites More sharing options...
DarkSuperHero Posted February 28, 2009 Share Posted February 28, 2009 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>'; Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773371 Share on other sites More sharing options...
cooldude832 Posted February 28, 2009 Share Posted February 28, 2009 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 Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773389 Share on other sites More sharing options...
Blunketts dog Posted February 28, 2009 Author Share Posted February 28, 2009 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 https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773472 Share on other sites More sharing options...
Blunketts dog Posted March 1, 2009 Author Share Posted March 1, 2009 i got it working by doing this: <?php $link = ' "http://www.yahoo.co.uk" '; $message = ' <html> <body> <p>Click <a href ='.$link.'>here </a>for yahoo</p> </body> </html>'; Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773715 Share on other sites More sharing options...
haku Posted March 1, 2009 Share Posted March 1, 2009 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 https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-773736 Share on other sites More sharing options...
shadiadiph Posted March 1, 2009 Share Posted March 1, 2009 oops sorry i forgot you needed the extra '' on the link definition Link to comment https://forums.phpfreaks.com/topic/147289-link-in-mail-not-working/#findComment-774200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.