Page 1 of 1

Can't use variables in php mail message

Posted: Sun Sep 13, 2009 12:54 pm
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?

Re: Can't use variables in php mail message

Posted: Sun Sep 13, 2009 1:26 pm
by jackpf
Umm...looks to me like you have nested PHP tags. Don't need them.

Re: Can't use variables in php mail message

Posted: Sun Sep 13, 2009 1:40 pm
by ViserExcizer
oh thanks, so silly of me, thats the last time im using a html editor to edit php

Re: Can't use variables in php mail message

Posted: Sun Sep 13, 2009 2:11 pm
by jackpf
Yeah, syntax highlighting is awesome. You'd probably have noticed it yourself otherwise.