Solved

how to show php variables in html email

Posted on 2016-09-24
4
42 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
  • 2
  • 2
4 Comments
 
LVL 49

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
 

Author Comment

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

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
 

Author Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parts and Products table schema in mysql 6 43
wamp versus xampp 4 43
<? versus <?php 5 36
Store image url and display it for user profile 6 23
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now