Page 1 of 1

php sending links via email

Posted: Tue Jul 13, 2010 10:10 pm
by Josh_Dude83
I'm trying to send an email from my code with a link to another page. Like so:

$subject = "Password Reset!";
$message = "Here is the link to reset your password: <a href='changepassword.php?id=2489&user=tom'>Link to Change Password</a> \r\n$userid, please don't forget it often!\n\n";
mail( $email, "Subject: $subject", $message, "From: someone@example.com" );

However, when I look it my email the link show up just as: <a href='changepassword.php?id=2489&user=tom'>Link to Change Password</a>
It's not actually a link. What am i doing wrong?

Re: php sending links via email

Posted: Tue Jul 13, 2010 10:11 pm
by jraede
You have to add e-mail headers to display the e-mail as HTML. But, 99% of e-mail clients automatically add links to e-mail addresses and URLs, so you can just write it out without the <a></a> tags and it will show up as a link.

Re: php sending links via email

Posted: Tue Jul 13, 2010 10:18 pm
by Josh_Dude83
isn't that what I did in the above code? It doesn't work.

Re: php sending links via email

Posted: Tue Jul 13, 2010 10:29 pm
by Josh_Dude83
Oh wow what a tard. Okay fixed it:

$subject = "Password Reset!";
$message = "Here is the link to reset your password: <ahref='http://...../changepassword.php?id=2489&user=tom'>Link to Change Password</a> \r\n$userid, please don't forget it often!\n\n";
mail( $email, "Subject: $subject", $message, "From: jap97@pitt.edu" );

I forgot to actually add the complete address. SO used to working on the local machine. Alright so...but the link still isn't showing up right.

Instead of:

Here is the link to reset your password: Link to Change Password
jap97, please don't forget it often!

Its showing up as:

Here is the link to reset your password: <ahref='http://.../changepassword.php?id=2489&user=tom'>Link to Change Password</a>
please don't forget it often!

Re: php sending links via email

Posted: Tue Jul 13, 2010 10:31 pm
by jraede
Right, like I said. You have to add headers to the e-mail via the mail() function in order to get it to properly display HTML tags. Because you don't have those headers, it will display like you have, with the tags among the text. You can either add the proper headers to get HTML to display, but it's pointless because e-mail clients automatically recognize links. Just type out the URL and it will show up as a link.

Re: php sending links via email

Posted: Tue Jul 13, 2010 10:44 pm
by Josh_Dude83
I have no idea how to user headers. Never taught that. I just want the link to show up as "A Link to change password" and not the actual link. Looking up headers now, but help would be appreciated.

Re: php sending links via email

Posted: Tue Jul 13, 2010 11:47 pm
by jraede
I don't know how to be more clear. Just send it with the URL typed out like www.reset-password.com. The e-mail client will turn it into a link. No need to use headers.

Re: php sending links via email

Posted: Wed Jul 14, 2010 1:31 am
by Josh_Dude83
URL typed out like www.reset-password.com. The e-mail
But I dont want to see www.reset-password.com in my email. I want to see "Change password". I want the link to appear as that string not the actual link itself. That's what I'm getting at.

Re: php sending links via email

Posted: Wed Jul 14, 2010 2:41 am
by jraede
Gotcha, then you'll have to use a content-type header. Check out example 3 on this site: http://www.w3schools.com/PHP/func_mail_mail.asp