partho
partho

Reputation: 1084

send link using php mail() function

User should get a email in the format:----- Copy the token: xxxxx And paste it in this Link ----- My codes:

$message="Copy the token:       ".
            token_generator(10)."       ".
            "And paste it in the link  "."<a href='recover_pass_get_mail.php'>Link</a>";

where xxxxx is returned by token_generator(10) function. but user gets in the format code is written

Upvotes: 1

Views: 16955

Answers (4)

Mohammad Alabed
Mohammad Alabed

Reputation: 809

There is many points you should think about them .. you can notice them in the following example code:

<?php

$fromTitle = "From Title";
$emailFrom = 'example_from@gmail.com';
$emailTo   = 'example_to@gmail.com';
$token = token_generator(10);

$subject = "Password Recovery"; 
$message = "Copy the token: $token And paste it in the link <a href='recover_pass_get_mail.php'>Link</a>";
$random_hash = md5(uniqid(time()));

$header = "From: $fromTitle <$emailFrom>\r\n";
$header .= "Reply-To: ".$emailFrom."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$random_hash."\"\r\n\r\n";
$header .= "This is token email.\r\n";
$header .= "--".$random_hash."\r\n";
$header .= "Content-type:text/html; charset=UTF-8\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";

@mail($emailTo, $subject, $message, $header);   


?>

Upvotes: 2

nomistic
nomistic

Reputation: 2962

There are some problems in your strings, however, here are a few things to consider here:

First all you might want to (just as a matter of practice) assign token_generator(10) to a variable on your script.

Something like this

$token = token_generator(10)

and pass $token to the script

Secondly you are having some trouble with the strings in your email. You don't need to wrap your link in a href tags (in fact it will be a problem if the user does not have HTML email turned on (as many do not). Just post the link itself.

Thirdly, why not just attach the token to the URL? It's an easier step for the user. Here's an example:

$message="Follow this link: http://(url)recover_pass_get_mail.php?token=$token";

and then you can just get the token from the URL using

$_GET['token'];

Upvotes: 1

Danny
Danny

Reputation: 871

seems like your email function doesn't have good react with html tags, you probably missing this in you'r $header object.

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

read this, https://css-tricks.com/sending-nice-html-email-with-php/

it has great explanation

Upvotes: 5

Pedro Lobito
Pedro Lobito

Reputation: 99031

Have you tried ?

$myToken = token_generator(10);
$message="Copy the token: $myToken And paste it in the link <a href='recover_pass_get_mail.php'>Link</a>";

DEMO

Upvotes: 0

Related Questions