0

Below is my php script: I have a page where a client fills in the form and the data gets proceced by this form and email me the data in nice tables. however the variables display instead of the data. (ie $name)

Please help.

<?php

$fullname=$_POST['fullname'];
$companyname=$_POST['companyname'];
$idnumber=$_POST['idnumber'];
$dob=$_POST['dob'];
$addressone=$_POST['addressone'];
$addresstwo=$_POST['addresstwo'];
$postalcode=$_POST['postalcode'];
$citystate=$_POST['citystate'];
$country=$_POST['country'];
$mobile=$_POST['mobile'];
$homework=$_POST['homework'];
$email=$_POST['email'];
$altemail=$_POST['altemail'];
$dob=$_POST['dob'];
$tc=$_POST['tc'];
$username=$_POST['username'];
$password=$_POST['password'];

//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Test HTML email'; 
//create a boundary string. It must be unique 
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time())); 
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: [email protected]\r\nReply-To: [email protected]";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<span style="font-family: Arial; font-size:16pt; color: #595959;"><strong>New Account Registration</strong></span><p>&nbsp;</p>

<span style="font-family: Arial; font-size:12pt; color: #595959;"> $fullname has filled in the following information:<p>
</span>


<table cellspacing"2" border="0" "cellpadding="5px" style="font-family: Arial; font-size: 11pt; color: #777777;">


<tr>  <!-- Full Name -->
     <td>* Full Name:</td>
     <td><?php echo '$fullname'; ?></td>
</tr>


<tr>  <!-- Company Name -->
     <td>* Company Name:</td>
     <td>$companyname</td>
</tr>

<tr>  <!-- ID Number / Passport Number -->
     <td>* ID Number / Passport No.</td>
     <td>$idnumber</td>
</tr>

<tr>  <!-- Date of Birth -->
     <td>* Date of Birth</td>
     <td>$dob</td>
</tr>

<tr><td><strong>&nbsp;</strong></td></tr>
<tr>  <!-- Address Line 1 -->
     <td>* Address Line 1</td>
     <td>$addressone</td>
</tr>
<tr>  <!-- Address Line 2 -->
     <td>* Address Line 2</td>
     <td>$addresstwo</td>
</tr>
<tr>  <!-- Postal Code  -->
     <td>* Postal Code</td>
     <td>$postalcode</td>
</tr>

<tr>  <!-- City / State  -->
     <td>* City / State</td>
     <td>$citystate</td>
</tr>

<tr>  <!-- Country  -->
     <td>* Country</td>
     <td>$country</td>
</tr>

<tr><td><strong>&nbsp;</strong></td></tr>

<tr>  <!-- Mobile Number  -->
     <td>* Mobile Number</td>
     <td>$mobile</td>
</tr>

<tr>  <!-- Home / Work  -->
     <td>* Home / Work No.</td>
     <td>$homework</td>
</tr>

<tr>  <!-- Email Address  -->
     <td>* Email Address:</td>
     <td>$email</td>
</tr>

<tr>  <!-- Alternate Address  -->
     <td>* Alternate Address:</td>
     <td>$altemail</td>
</tr>
<tr><td><strong>&nbsp;</strong></td></tr>
<tr>  <!-- Username -->
     <td>* Username:</td>
     <td>$username</td>
</tr>
<tr>  <!-- Password -->
     <td>* Password:</td>
     <td>$password</td>
</tr>
<tr>  <!-- Terms and Conditions -->
     <td colspan="2">$tc Agreed to the <a href="http://www.test.html">Terms & Conditions</a>.</td>
     <td></td>
</tr>
</table>
--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

3 Answers 3

2

You're missing <?php echo $variable ?> everywhere. PHP code only executes if it's held within <?php ?> bracket pairs. Otherwise it's just "text" and gets output directly. None of the variables in your form are being treated as PHP code, hence coming out as text, not their contents.

Sign up to request clarification or add additional context in comments.

2 Comments

I see, but i do have by the First Name comment block, and it still wont work. Surely that one should at least work?
No, because you're doing echo '$variable'. single-quoted strings do not interpolate variables, so you're outputting a literal '$variable' text, not the contents of the $variable. You'd need to do echo $variable or echo "$variable" instead.
0

Maybe for every var do this:

<?php echo $varname; ?>

2 Comments

I did that to the First Name comment block, but not working. Surley that $name should work?
Yeah. Look at the post from Marc B. I give you an example: <tr> <!-- Full Name --> <td>* Full Name:</td> <td><?php echo $fullname; ?></td> </tr>
0

One example for all:

<span style="font-family: Arial; font-size:12pt; color: #595959;"> $fullname has filled in the following information:<p>

This is wrong.

Variables need to be print (with either echo or print function in PHP script on server side).

But if php settings on your webserver allow it, you can use short form <?=$fullname?> instead of $fullname, which is syntactic sugar without typing echo/print function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.