Как отправить гиперссылку в теле сообщения с помощью php mail? - PullRequest
0 голосов
/ 28 июня 2018

код:

$to = "salman.saifi4@gmail.com";
$subject = $subjects;
$txt = "Name:\t".strip_tags($name)."\n\n"."Subject:\t".strip_tags($subject)."\n\n"."Leave Date:\t".$leave_date."\n\n"."Reason:\t".strip_tags($reason)."\n\n".strip_tags("<a href='http://example.com/confirm.php'>Click Here If Leave Application Approve</a>")."\n\n".strip_tags("<a href='http://example.com/not-confirm.php'>Click Here If Leave Application Not Approve</a>");
$headers = "Leave Application";

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

Я использую простую почтовую функцию в php и хочу отправить ссылку, как показано в моей переменной $ txt, когда я отправляю электронное письмо, моя ссылка выглядит так, как показано ниже:

<a href='http://example.com/confirm.php'>click here if leave application approve</a>
<a href='http://example.com/not-confirm.php'>click here if leave application not approve</a>

Но мне нужен только текст внутри тега href т.е. , Итак, как я могу это сделать? Пожалуйста, помогите мне.

Спасибо

Ответы [ 2 ]

0 голосов
/ 28 июня 2018

Так вы можете отправлять html по почте. вы можете установить ваше сообщение в переменной $ message

$to = "salman.saifi4@gmail.com";
$subject = $subjects;
$message = "<a href='http://example.com/confirm.php'>click here if leave application approve</a>
<a href='http://example.com/not-confirm.php'>click here if leave application not approve</a>";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

mail($to,$subject,$message,$headers);
0 голосов
/ 28 июня 2018

Вам нужно добавить следующее в заголовки:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

А также для текста:

$text = '<html><body>';
$text.= '<a href="http://example.com/confirm.php">click here if leave application approve</a>';
$text.= '<a href="http://example.com/not-confirm.php">click here if leave application not approve</a>';
$text.= '</body></html>';
...