Jump to content

Question: Is it posible to use PHP vars inside an HTML email?


T2theC

Recommended Posts

Hi guys,

 

I have created a form that posts to an email address. Simple enough!

 

There is quite a bit of content in this form and at the moment it doesn't display very nicely for the client.

 

I am pulling the info from the form like this:

$firstname = strip_tags ($_REQUEST['firstname']);

 

It works finr in a normal text email. I have tried using the var in the email like this:

<td> $firstname </td>   and also:  <td> <?php $firstname ?> </td>

 

Neither pull the info across.

 

I also use an online shopping cart system that uses:

%%GLOBAL[yadda yadda] [firstname]

 

From my limited understanding, I take it this is being pulled from a global ini file?????

 

Basically, is there anyway of 'easily' sorting this out so the data pulled form the form displays nicely in a table???

 

Thank in advance for all your help.

Adding a variable within php tags will not result in anything. If you want to print the contents of the variable to the screen you need to echo it

<td> <?php echo $firstname ?> </td>

 

also use an online shopping cart system that uses:

%%GLOBAL[yadda yadda] [firstname]

From my limited understanding, I take it this is being pulled from a global ini file?

This has nothing to do with PHP. This is handled by your shopping cart script.

Right then,

 

This is still not working :-(

 

The table comes across fine so the HTML side is working ok.

 

But the form content isn't there. There is no code in its place. Its just blank.

 

I have put in:

<td><P><?php echo $firstname ?> </p><td>

OK Thanks WildTeen88

 

Here it is:

<?php
  $firstname = strip_tags ($_REQUEST['firstname']);
  $surname = strip_tags ($_REQUEST['surname']);
  $position = strip_tags ($_REQUEST['position']);
  $compname = strip_tags ($_REQUEST['compname']);
  $email = strip_tags ($_REQUEST['email']);
  $phone = strip_tags ($_REQUEST['phone']);
  $address = strip_tags ($_REQUEST['address']);
  $postcode = strip_tags ($_REQUEST['postcode']);
  $comptype = strip_tags ($_REQUEST['comptype']);
  $area = strip_tags ($_REQUEST['area']);
  $other = strip_tags ($_REQUEST['other']);
  $employees = strip_tags ($_REQUEST['employees']);
  $established = strip_tags ($_REQUEST['established']);
  $turnover = strip_tags ($_REQUEST['turnover']);
  $profit = strip_tags ($_REQUEST['profit']);
  $sector = strip_tags ($_REQUEST['sector']);
  $overview = strip_tags ($_REQUEST['overview']);
  $challenge = strip_tags ($_REQUEST['challenge']);
  $overcome = strip_tags ($_REQUEST['overcome']);
  $achieved = strip_tags ($_REQUEST['achieved']);
  $mentor = strip_tags ($_REQUEST['mentor']);
  $question = strip_tags ($_REQUEST['question']);
  $terms = strip_tags ($_REQUEST['terms']);
  $contact = strip_tags ($_REQUEST['contact']);


$message ='

  <html>
<head>
<title>MY TITLE</title>
</head>
<body>
<table>
  <tr>
    <td width="181" valign="top" bgcolor="#A2C7DA"><p><strong>First Name:</strong></p></td>
    <td width="306" valign="top" bgcolor="#A2C7DA"><p><?php echo $firstname ?></td>
</tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Surname:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $surname ?></p></td>
</tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Position:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $position ?>
    </p></td>
</tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Company Name:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $compname ?></p></td>
</tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>E-mail:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $email  ?></p></td>
</tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Telephone:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $phone ?></p></td>
</tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Address:</strong></p></td>
    <td rowspan="3" valign="top" bgcolor="#A2C7DA"><p><?php echo $address ?></p></td>
</tr>
  <tr valign="top">
    <td bgcolor="#A2C7DA"><p> </p></td>
  </tr>
  <tr valign="top">
    <td bgcolor="#A2C7DA"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Post Code:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $postcode ?></p></td>
</tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Legal Structure:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><?php echo $comptype ?></td>
  </tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>What sector<br />
      are you in?</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $area $other ?></p></td>
</tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>No. of employees:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><?php echo $employees ?></td>
  </tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>When was the company established?</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $established ?></p></td>
</tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Turnover:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $turnover ?></p></td>
</tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Profit last year:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $profit ?></p></td>
  </tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Sector:</strong></p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $sector ?></p></td>
</tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Provide some background information and an overview of your organisation: </strong><br />
      (max 200 words)</p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $overview ?></p></td>
  </tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Give details of the challenge or opportunity that you faced?</strong><br />
      (max 200 words)</p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $challenge ?></p></td>
  </tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Tell us what you have done to overcome the challenge or maximize the opportunity:</strong><br />
      (max 500 words)</p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $overcome ?></p></td>
  </tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Provide details of<br />
      what has been achieved as a result:</strong><br />
      (max 200 words)</p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $achieved ?></p></td>
  </tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>Tell us what you want a business mentor?</strong><br />
      (max 200 words)</p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $mentor ?></p></td>
  </tr>
  <tr>
    <td valign="top"></td>
    <td valign="top"><p> </p></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#A2C7DA"><p><strong>What question would you as a business mentor?<br />
    </strong>(max 50 words)</p></td>
    <td valign="top" bgcolor="#A2C7DA"><p><?php echo $question ?></p></td>
  </tr>
  <tr>
    <td valign="middle"> </td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="2" valign="middle" bgcolor="#A2C7DA"><p><strong>I confirm I have read and accept the terms and conditions: </strong><?php echo $terms ?></p></td>
</tr>
  <tr>
    <td colspan="2" valign="middle" bgcolor="#A2C7DA"><p>I am happy for Business Link to contact me: <?php echo $contact ?></p></td>
  </tr>
  
</table>

</body>
</html>

';


// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers

$headers .= 'From: ME <[email protected]>' . "\r\n";


// Mail it
mail("[email protected]", "Competiton Entry", $message, $headers);



?>

The way you have coded it is wrong.

 

Your HTML needs to be wrapped in quotes you cant do

$var = <html><bah><?php echo $foo; ?></blah><html>

 

It needs to be like

$var = "<html><bah>$foo</blah><html>"

 

However if you have lot of HTML you can use the HEREDOC sytax

$var = <<<HTML
<html><bah>$foo</blah><html>
HTML;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.