Can't use variables in php mail message

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ViserExcizer
Forum Newbie
Posts: 24
Joined: Tue Nov 25, 2008 1:17 pm

Can't use variables in php mail message

Post by ViserExcizer »

Why can't I echo variables in php mail message?

for instance,

Code: Select all

 
 
// multiple recipients
$to  ='xxxxxxxx@gmail.com'; // note the comma
 
 
// subject
$subject = 'Ticket ORDER';
 
// message
$message = '
<html>
<body>
  <h2>You have one ORDER!</h2>
    
  <table border="1">
    <tr>
      <td>FullName</td><td>'.'<? echo $fullname;?>'.'</td>
    </tr>
    <tr>
      <td>Position</td><td>'.'<? echo $position;?>'.'</td>
    </tr>
    <tr>
      <td>Email</td><td>'.'<? echo $email;?>'.'</td>
        </tr>
        <tr>
      <td>Office Tel</td><td>'.'<? echo $officephone;?>'.'</td>
        </tr>
        <tr>
      <td>Mobile Phone</td><td>'.'<? echo $mobilephone;?>'.'</td>
        </tr>
        <tr>
      <td>Home Address</td><td>'.'<? echo $haddress;?>'.'</td>
        </tr>
        <tr>
      <td>Company</td><td>'.'<? echo $company;?>'.'</td>
        </tr>
        <tr>
      <td>Company Addr</td><td>'.'<? echo $caddress;?>'.'</td>
        </tr>
        <tr>
      <td>Ticket type</td><td>'.'<? echo $tix1;?>'.'</td>
        </tr>
        <tr>
      <td>Event</td><td>'.'<? echo $tix2;?>'.'</td>
        </tr>
        <tr>
      <td>Tickets</td><td>'.'<? echo $tix;?>'.'</td>
        </tr>
        <tr>
      <td>Price</td><td>'.'<? echo $price;?>'.'</td>
        </tr>
  </table>
</body>
</html>
';
 
 
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
// Additional headers
$headers .= 'To: xxxxxx <xxxxxxxx@gmail.com>' . "\r\n";
$headers .= 'From: Order <admin@xxxxxxx.com>' . "\r\n";
 
// Mail it
mail($to, $subject, $message, $headers);
 
                    
    
 
 
 
 

All the echoed variables $fullname, $position, $email until $price doesn't appear in the mail, and is just blank. These arent null or empty variables, because they are echoed in the php page that holds this script, and comes out fine, but the same variable doesnt appear in the mail. how do I include them?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Can't use variables in php mail message

Post by jackpf »

Umm...looks to me like you have nested PHP tags. Don't need them.
ViserExcizer
Forum Newbie
Posts: 24
Joined: Tue Nov 25, 2008 1:17 pm

Re: Can't use variables in php mail message

Post by ViserExcizer »

oh thanks, so silly of me, thats the last time im using a html editor to edit php
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Can't use variables in php mail message

Post by jackpf »

Yeah, syntax highlighting is awesome. You'd probably have noticed it yourself otherwise.
Post Reply