?
Solved

how to show php variables in html email

Posted on 2016-09-24
4
Medium Priority
?
83 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

762 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