Calling value of string to email_template.html using PHPMailer

rsbypi4

New member
I making contact using php, Now the PHPMailer is working properly.
My problem is, How to call the value from one page to other page and here my code.


Contact.php
PHP:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require './mail/mail-src/Exception.php';
require './mail/mail-src/PHPMailer.php';
require './mail/mail-src/SMTP.php';

$page_content =  file_get_contents('./mail/email_HTMLTemplate.php');
$mail = new PHPMailer(true);
$mail -> isSMTP();
$mail -> Host = 'smtp.gmail.com';
$mail -> SMTPAuth = true;
//sender info
$mail -> Username = 'sample@gmail.com';
$mail -> Password = 'pass0987';
$mail -> SMTPSecure = 'ssl';
$mail -> Port = 465;

$mail -> setFrom($c_email);
$mail -> addAddress('sample_admin@gmail.com');
$mail -> isHTML(true);
//$mail -> Subject = ('User_Inquiry');


$email_subject = 'User_Inquiry';
$mail -> Subject = $email_subject;


$mail-> Body = $page_content;
$mail ->send();
$succ = "success";

My contact page is once the user click the submit button they going to send a email to the admin with the email_HTMLTemplate.php and here my code of the HTMLTemplate.php I could not right all the code because it's to long and here the main part of the code.

email_HTMLTemplate.php
HTML:
<!doctype html>
<html>
<?php include('contact.php');?>
<head>
 <!--<![sample only]-->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="background-color:#f9f9f9;">

  
 <tr>
<td align="center" style="font-size:0px;padding:10px 25px;padding-bottom:40px;word-break:break-word;">
<div style="font-family:'Helvetica Neue',Arial,sans-serif;font-size:32px;font-weight:bold;line-height:1;text align:center;color:#555;">
<!--STRING VARIABLE HERE-->
<?php echo $email_subject;?>
                                   
</div>
</td>
</tr>



</body>
</html>

MY PROBLEM:
I want to call the string value of
PHP:
$mail -> Subject = ('User Inquiry');
from Contact.php to my email_HTMLTemplate.php
PHP:
<?php echo $email_subject;?>
.
 
There is an undefined variable $c_email in the setFrom method. Make sure that the variable $c_email is defined and contains a valid email address before it is passed to the setFrom method.
 
There is an undefined variable $c_email in the setFrom method. Make sure that the variable $c_email is defined and contains a valid email address before it is passed to the setFrom method.
Good day Moorcam, there is no problem with $c_email it's working properly. My problem is how to pass the value of string from
PHP:
$mail -> Subject = ('User Inquiry');//<------------This string I want to pass into email_HTMLTemplate.php
the text User_Inquiry I want to pass into email_HTMLTemplate.php,
HTML:
 <tr>
<td align="center" style="font-size:0px;padding:10px 25px;padding-bottom:40px;word-break:break-word;">
<div style="font-family:'Helvetica Neue',Arial,sans-serif;font-size:32px;font-weight:bold;line-height:1;text align:center;color:#555;">

<?php echo $email_subject;?> <!--<----------I WANT TO PASS HERE --->
                                 
</div>
</td>
</tr>

I want to display the string value of $email_subject dynamically.
 
Code:
$email_subject = 'User Inquiry'; // This is your string value
$mail->Subject = $email_subject; // Assigning the variable to the subject
The subject of the email will be set to whatever value is stored in $email_subject. If you want to dynamically change the subject later, just update the $email_subject variable, and it will reflect in the email subject when you send it.
 
Code:
$email_subject = 'User Inquiry'; // This is your string value
$mail->Subject = $email_subject; // Assigning the variable to the subject
The subject of the email will be set to whatever value is stored in $email_subject. If you want to dynamically change the subject later, just update the $email_subject variable, and it will reflect in the email subject when you send it.
Good day Moorcam, I have a image below please take a look.
mail.png
 
In your code that sends you the email, specifically the body of the message. Where are you echoing $c_email?
 
Back
Top