Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-03-23
13
Medium Priority
?
364 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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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
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!

 

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

Industry Leaders: 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …
Suggested Courses

971 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