Solved

How can I use a $_SESSION[Firstname]  variable in the $mail->Body part of the email

Posted on 2014-03-23
13
319 Views
Last Modified: 2014-03-23
I'm using a php script to send an email with a html body. In the body I would like to use SESSION variables to form part of the body.
Here is the body code:
$mail->Body    = '<h1>Extra Leverage</h1> Your application to become a Member has been accepted.<p>Welcome.';
I tried the following but it doesn't show up in the email body:
$mail->Body    = '<h1>Extra Leverage</h1> <?php echo $_SESSION[Firstname]<br />; ?>
Your application to become a Member has been accepted.<p>Welcome.';
0
Comment
Question by:dynorich
  • 6
  • 6
13 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39949117
Use $_SESSION['Firstname']: don't forget quotes.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39949119
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39949120
Try this.
$mail->Body    = '<h1>Extra Leverage</h1> ' . $_SESSION['Firstname'] . '<br />
Your application to become a Member has been accepted.<p>Welcome.'; 

Open in new window

0
 

Author Comment

by:dynorich
ID: 39949128
I tried:
$mail->Body    = '<h1>Extreme Leverage</h1> <?php echo $_SESSION['Firstname']; ?><br/>Your application to become a Member has been accepted.<p>Welcome.';
and got error:
Parse error: syntax error, unexpected T_STRING in /home3/dynorich/public_html/extraleverage/noc/purchase_member.php on line 234
0
 

Author Closing Comment

by:dynorich
ID: 39949136
Thank you. It worked perfectly!
0
 

Author Comment

by:dynorich
ID: 39949145
When I tried to add another variable, I got this error
$mail->Body    = '<h1>Extra Leverage</h1> ' . $_SESSION['Firstname'] . S_SESSION['cid']'<br />
Your application to become a Member has been accepted.<p>Welcome.';

Parse error: syntax error, unexpected '[' in /home3/dynorich/public_html/extraleverage/noc/purchase_member.php on line 234
0
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.

 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39949146
You forgot  a dot:

$mail->Body    = '<h1>Extra Leverage</h1> ' . $_SESSION['Firstname'] . S_SESSION['cid'] . '<br />
Your application to become a Member has been accepted.<p>Welcome.';
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39949148
Keep in mind you didn't leave any blank space between the two variables so if the first name is Marco and the cid i 123 you'll get Marco123.
0
 

Author Comment

by:dynorich
ID: 39949156
Still got same error
0
 

Author Comment

by:dynorich
ID: 39949159
should I post this as a new question so you get the points?
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39949169
As you wish... but have you still the error?
0
 

Author Comment

by:dynorich
ID: 39949174
No. It's working now.
Thanks very much
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39949178
:)
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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

911 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

20 Experts available now in Live!

Get 1:1 Help Now