Jump to content

Link to site in mail function


shirvo

Recommended Posts

$to = "tom@hotmail.com";
$subject = "Registered";
$body = "hello";
mail($to, $subject, $body)

In the "$body" i want to have a link in there so when people get the email they can click it and go to an activation page. What code do i use to add that link??? Please help
Link to comment
Share on other sites

The mail() function as you've described it above, sends a text-based email.  So, you could simply type out the link like this - http://www.mysite.com - and then it's up to the recipient's email client as to whether or not it gets displayed as a link or as text.  You won't have control of that.

If you want to send HTML mail, it gets a bit more complicated because you have to send a bunch of headers in the mail() function.  However, then you would be able to send a link, and, assuming the recipient can receive an HTML email, they will see the link as you describe it in HTML (e.g. <a href="http://www.mysite.com">My site</a>)
Link to comment
Share on other sites

Here are some decent headers for that..

[code=php:0]
$headers = "FROM: your_email_address\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative;\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit";
$headers .= "\r\n";
[/code]

Hope that helps,
Tom
Link to comment
Share on other sites

nope that still doesn't help.

$headers = "FROM: activation@ausfamily.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative;\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit";
$headers .= "\r\n";

$to = $email;
$subject = "Registered";

$body = "<html><body>hi <a href=\"www.ausfamily.com/authentication.php"\>Activation</a></body></html>";

mail($to, $subject, $body, $headers);

This is my code and the page wont even work. Please help. i really need to have this work
Link to comment
Share on other sites

Those are good headers.  The only thing I can see in the above code that wouldn't work is you missed where you escaped a " in the URL.  That would cause a parse error.  Try:

[code]
$headers = "FROM: activation@ausfamily.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative;\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit";
$headers .= "\r\n";

$to = $email;
$subject = "Registered";

$body = "<html><body>hi <a href=\"www.ausfamily.com/authentication.php\">Activation</a></body></html>";

mail($to, $subject, $body, $headers);
[/code]
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.