Solved

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

Posted on 2014-03-23
13
314 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 30

Expert Comment

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

Expert Comment

by:Marco Gasi
ID: 39949119
0
 
LVL 82

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 30

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 30

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 30

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 30

Expert Comment

by:Marco Gasi
ID: 39949178
:)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

757 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

21 Experts available now in Live!

Get 1:1 Help Now