Moe Moe - 23 days ago 7
HTML Question

My $link doesn't work in a href='mailto'

This is how i get my link

$link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];


And this is how it looks when i echo it
echo 'My link : ' . $link;


http://www.mylink.com/myfile.php?int=&int1=ASD++

But when i put my link in

echo "<a href='mailto:$mail&subject=Aktiviteter&body=$link'>Press on the link</a>";


I only get

http://www.mylink.com/myfile.php

So i miss my ?int=&int1=ASD++ , how can i get it to? Sorry if im unclear.

Answer

Your link is being considered part of the string that builds the email.

Your email client is seeing the request as:

  subject = Aktiviteter
  body = http://www.mylink.com/myfile.php?int=
  int1 = ASD++

Because the email client doesn't know what to do with "int1", it ignores it.

To get around this, you'll want to encode your $link variable into the mailto URL using PHP's urlencode function.

Try this:

<?php
    $link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
    $encoded = urlencode($link);
    echo "<a href='mailto:$mail?subject=Aktiviteter&body=$encoded'>Press on the link</a>";
?>