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
Solved

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

Posted on 2014-03-23
13
329 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP query / monitor data from Telnet to MySQL 7 48
Wordpress French and English Site 6 77
Wordpress Pagination 1 28
Correct syntax for subdirectories 9 18
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 count occurrences of each item in an array.

856 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