send link using php mail() function

大憨熊 提交于 2019-12-06 07:47:38

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

Mohammad Alabed

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);   


?>

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'];

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!