Php邮件从上一页提取表单数据

时间:2014-06-06 09:13:52

标签: php html css email

所以我在一个php上填写了一个表格,如下所示:

<p>
  <label for="first_name">First Name: </label>
  <input type="text" size="30" name="first_name" id="first_name"/>
</p>
<p>
  <label for="last_name"> Last Name:</label>
  <input type="text" size="30" name="last_name" id="last_name"/>
</p>
<p>
  <label for="address_street">Street:</label>
  <input type="text" size="30" name="address_street" id="address_street"/>
</p>
<p>
  <label for="address_city">City:</label>
  <input type="text" size="30" name="address_city" id="address_city"/>
</p>
<p>
  <label for="address_state">State/Province:</label>
  <input type="text" size="30" name="address_state" id="address_state"/>
</p>
<p>
  <label for="email">Your  e-mail: </label>
  <input type="text" size="30" name="email" id="email"/>
</p>
<p>
  <label for="phone">Your phone number: </label>
  <input type="text" size="30" name="phone" id="phone"/>
</p>

这是在一个php页面上。从这里开始,它转到另一个php,其中一部分包含用于向收件人发送html电子邮件的脚本。

问题是,即使我认为我正确地声明它们并将它们正确地混合到html中,我似乎也无法得到它来拉变量。

<?php
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $to = "devtech8@gmail.com, example@gmail.com";
  $subject = "HTML email for ALPS";

  $message .= '
  <html>
    <body>
      <div style="display: inline-block; width: 28%; float: left;">
        <img src="http://englishintheusa.com/images/alps-logo.jpg" alt="ALPS Language School" />
      </div>
      <div style="display: inline-block; width: 68%; float: right;">
        <p style="color: #4F81BD; font-size: 20px; text-decoration: underline;">Thanks You For Your Inquiry!</p>
      </div>
      <div style="padding-left: 20px; color: #666666; font-size: 16.8px; clear: both;">
        <p>Dear $first_name $last_name ,</p>
        </br >
        <p>Thank you for the following inquiry:</p>
        </br >
        </br >
        </br >
        </br >
        <p>****Comment goes here****</p>
        </br >
        </br >
        <p>We will contact you within 2 business days.  Our office is open Monday-Friday, 8:30 AM - 5:00 PM Pacific Standard Time.</p>
        </br >
        <p>Thank you for your interest!</p>
        </br >
        </br >
        <p>Best Regards,</p>
        </br >
        </br >
        <p>ALPS Language School</p>
        </br >
        </br >
        <p>430 Broadway East</p>
        <p>Seattle WA 98102</p>
        <p>Phone: 206.720.6363</p>
        <p>Fax: 206. 720.1806</p>
        <p>Email: info@englishintheusa.com</p>
      </div>
    </body>
  </html>';

  // Always set content-type when sending HTML email
  $headers .= "MIME-Version: 1.0" . "\r\n";
  $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

  // More headers

  mail($to,$subject,$message,$headers);
?>

所以你看到我想要获得first_namelast_name的位置。好吧,它没有正确出来。

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:0)

$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];

它将从cookie,post或get中发送的请求中获取数据。

答案 1 :(得分:0)

使用此

....'+$variables+'...

因为当你使用&#39;&#39;你无法从你需要的变量中获得一个值,使用&#34;&#34;调用变量

例如

<?php 
    $t = 'test';
    echo "$t"; // will result test
    echo '$t'; // will result $t
?>

答案 2 :(得分:0)

错误背后的原因是<form>标记不正确。它应该是:

<form action="students_conf.php" method="post" id="contactform">