0

I'm trying to create a hyperlink that sends together with the E-mail. I've tried to find information on how to do this but I keep hitting a brick wall.

The third $message. variable should have a hyperlink but I dont seem to make it work. How do I make a hyperlink out of the third $message. variable and how do I include it in the mail function?

The PHP code for sending mail and hyperlink

$confirm_code=md5(uniqid(rand()));
$from=$_POST['minemail'];
$email=$_POST['kanemail'];
$subject=$_POST['subject'];
$message=$_POST['message'];
$message.="<br>Klicka på den här länken för att påbörja provet\r\n";
$message.="welcomeuser.php?passkey=$confirm_code"; //hyperlink

$company="dashboardcompany.php";

$sql= "INSERT INTO temp_members_db(confirm_code, email) VALUES('$confirm_code', '$email')";


$result=$connect->query($sql);


mail($email, $subject, $message, "Från: ".$from);

print "Ditt meddelande har skickats: <br>$email<br>$subject<br>$message<br>";
PHP Scrub
  • 171
  • 3
  • 17
  • 1
    **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Dec 17 '15 at 22:18
  • 1
    this is HTML 101 stuff. Plus, you need to use a full http:// call when hyperlinking, otherwise it won't work. – Funk Forty Niner Dec 17 '15 at 22:21
  • put it in href in a tag – Gogul Dec 17 '15 at 22:23

2 Answers2

3

You have to wrape text with HTML tag for url. Just use something like:

$message.="<a href=\"http://www.example.com/welcomeuser.php?passkey=$confirm_code\">"; //hyperlink
doubler
  • 121
  • 7
1

When including a hyperlink via Email/Internet, a full (external) http:// call is required, otherwise when a user clicks on the hyperlink, it will try and open a document from the user's (local) computer.

$message.="<a href='"."http://www.example.com/welcomeuser.php?passkey=$confirm_code".">welcomeuser.php?passkey=$confirm_code</a>";

References:

On an added note:

Your present code is open to SQL injection. Use mysqli_* with prepared statements, or PDO with prepared statements.

Community
  • 1
  • 1
Abhishek Singh
  • 369
  • 2
  • 17