Php电子邮件脚本

Php电子邮件脚本,php,forms,Php,Forms,下面是我的php脚本:我有一个页面,客户机在其中填写表单,数据通过此表单处理,并通过电子邮件将数据发送到nice表格中。但是,显示的是变量而不是数据。(即$name) 请帮忙 <?php $fullname=$_POST['fullname']; $companyname=$_POST['companyname']; $idnumber=$_POST['idnumber']; $dob=$_POST['dob']; $addressone=$_POST['addressone']; $a

下面是我的php脚本:我有一个页面,客户机在其中填写表单,数据通过此表单处理,并通过电子邮件将数据发送到nice表格中。但是,显示的是变量而不是数据。(即$name)

请帮忙

<?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 = 'test@test.com';
//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: test@test.com\r\nReply-To: test@test.com";
//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";
?>

--PHP alt-
内容类型:text/html;charset=“iso-8859-1”
内容传输编码:7bit
新帐户注册

$fullname已填写以下信息:
你到处都找不到
。PHP代码仅在其位于括号对内时执行。否则它只是“文本”并直接获得输出。表单中没有一个变量被视为PHP代码,因此显示为文本,而不是其内容。

对于每个变量,可以这样做:

<?php echo $varname; ?>

举一个例子:

<span style="font-family: Arial; font-size:12pt; color: #595959;"> $fullname has filled in the following information:<p>
$fullname已填写以下信息:
这是错误的

变量需要打印(在服务器端的PHP脚本中使用echo或print函数)


但是如果您的Web服务器上的php设置允许,您可以使用缩写形式而不是$fullname,这是一种语法糖,无需键入echo/print函数。

我明白了,但我有按名字的注释块,它仍然无法工作。当然这至少应该起作用吗?不,因为你在做
echo'$variable'
。单引号字符串不插入变量,因此输出的是文本“$variable”,而不是$variable的内容。您需要改为执行
echo$variable
echo“$variable”
操作。我对First Name注释块执行了此操作,但不起作用。Surley那$name应该有用吧?是的。看看Marc B的帖子。我给你举个例子:*全名: