Solved

how to show php variables in html email

Posted on 2016-09-24
4
76 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 52

Accepted Solution

by:
Ryan Chong earned 500 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 52

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

695 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