Moe Moe - 1 year ago 68
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;

But when i put my link in

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

I only get

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

Answer Source

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

Your email client is seeing the request as:

  subject = Aktiviteter
  body =
  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:

    $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>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download