Issue
Am trying to pass certain php variable as part of a clickable link to be send via PhpMailer. To this effect, I referenced a solution here but still cannot get it to work
source
$site = 'http://example.com';
$user_id = 100;
$msg="Please Click links below.<br> <br>
<a href='$site/link1.php?id=$user_id'>Link 1</a><br><br>
<a href='$site/link2.php'>Link 2</a>";
$msg_body = "Here is your $msg";
Here is my issue: When I run the Code, the Email get sent successfully but both link1 and link 2 are not clickable.
here is the code below
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
$site = 'http://example.com';
$user_id = 100;
$msg="Please Click links below.<br> <br>
<a href='$site/link1.php?id=$user_id'>Link 1</a><br><br>
<a href='$site/link2.php'>Link 2</a>";
$msg_body = "Here is your $msg";
//PHP Mailer Server settings goes here
$mail->setFrom('[email protected]', "Henry Good");
$mail->addAddress([email protected], 'Ann Ball); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'My Email Subject';
$mail->Body = $msg_body;
$mail->AltBody = $msg_body; // for Plain text for non-HTML mails
$sent = $mail->send();
Solution
Try to do something like that:
$mail->Body = html_entity_decode($msg_body);
or$mail->set('Body', $msg_body);
- In any way try to wrap your message body in
<html></html>
to get a valid code. Something like my sample below:
$mail->Body = sprintf('<html><body>%s<body><html>', $msg_body);
I hope something from that will help you sort your issue.
Answered By – Juljan
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0