Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to show php variables in html email

Posted on 2016-09-24
4
Medium Priority
?
90 Views
Last Modified: 2016-09-24
I am using php mailer and I can send html emails where the email is coming from a separate php file. Example:

 $m->Body = file_get_contents('basic-email-template/registration.php');

Open in new window


On the page where the user inputs their details I have:

 $_SESSION['firstname'] = clean_user_input($_POST['user_firstname']);

Open in new window


Then in the actual email received I have:

<h3>Hi, <?php echo $_SESSION['firstname'];?> !</h3>

But, the email is just showing Hi,          and no first name is displayed.

It's obviously meant to show the name from the session variable but doesn't.
0
Comment
Question by:Black Sulfur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 41813684
in your file that become the email body, you can create a custom tag (or anything to be marked that need to be replaced) in it, and when necessary, just replace it with the value you wanted.

like in registration.php, try define:
<h3>Hi, <SESSION[firstname]></h3>

Open in new window

then in your php, just do a replace:

$body = file_get_contents('basic-email-template/registration.php');
$body = str_replace("<SESSION[firstname]>", $_SESSION['firstname'], $body);
$m->Body = $body;

Open in new window

0
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41813692
That worked, thanks! Is it necessary to unset the session?
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41813695
>>Is it necessary to unset the session?
if you're no longer using session, yes you can unset it.
0
 
LVL 1

Author Comment

by:Black Sulfur
ID: 41813698
Thanks so much!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question