Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

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

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
dynorich
Asked:
dynorich
  • 6
  • 6
1 Solution
 
Marco GasiFreelancerCommented:
Use $_SESSION['Firstname']: don't forget quotes.
0
 
Marco GasiFreelancerCommented:
0
 
Dave BaldwinFixer of ProblemsCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dynorichAuthor Commented:
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
 
dynorichAuthor Commented:
Thank you. It worked perfectly!
0
 
dynorichAuthor Commented:
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
 
Marco GasiFreelancerCommented:
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
 
Marco GasiFreelancerCommented:
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
 
dynorichAuthor Commented:
Still got same error
0
 
dynorichAuthor Commented:
should I post this as a new question so you get the points?
0
 
Marco GasiFreelancerCommented:
As you wish... but have you still the error?
0
 
dynorichAuthor Commented:
No. It's working now.
Thanks very much
0
 
Marco GasiFreelancerCommented:
:)
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!

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now