I'm beginner on php. and now I want to set up $contact_name display in send email ? Below my code and please fix my code. email receive always show "$contact_name" not "my name"
<?php
if(isset($_POST['send_email']))
{
require_once('../src/PHPMailer.php');
require_once('../src/SMTP.php');
require_once('../src/Exception.php');
require_once('../vendor/autoload.php');
$mail = new phpmailer\phpmailer\PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2; // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$contact_name = $_POST['contact_name']; // required
$mail->From = '[email protected]';
$mail->FromName = 'No Reply';
$mail->AddAddress('[email protected]'); // Add a recipient
$mail->AddAddress; // Name is optional
$mail->IsHTML(false); // Set email format to HTML
$mail->Subject = 'Add Contact';
$mail->Body = 'Dear All, ($contact_name) with $contact_ext has been addeds.';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
}
?>
Change:
$mail->body
with
$mail->MsgHTML($message);
It Works Now. Thanks