【问题标题】:Php mail pulling form data from previous pagephp邮件从上一页拉取表单数据
【发布时间】:2014-07-27 12:13:43
【问题描述】:

所以我在一个 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。好吧,它没有正确输出。

有人可以帮忙吗?

【问题讨论】:

  • 此外, 没有做好他们的工作。嵌入php时不能这样吗?
  • 你的表单中有动作和方法吗?
  • font-size: 16.8px; ?哇,太准确了。你没有显示你的&lt;form&gt; 标签
  • 首先将&lt;/br &gt; 更改为&lt;br /&gt;
  • 这里是表单标签:
    englishintheusa.com/students_conf.php" method="post" id="contactform">

标签: php html css email


【解决方案1】:
$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];

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

【讨论】:

  • 它与问题无关。该问题没有提供足够的信息(例如&lt;form&gt;标签)
  • 但是,如果他使用
    提交数据,那么我们可以使用给定的行来获取它。
  • true,但获取变量的范围要尽量精确,避免可能的变量冲突(如$_GET['first_name'] != $_POST['first_name']
【解决方案2】:

使用这个

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

因为当你使用 '' 时你无法从你需要的变量中获取值,所以使用 "" 来调用一个变量

例如

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

【讨论】:

    【解决方案3】:

    错误背后的原因是&lt;form&gt;标签不正确。应该是:

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

    【讨论】:

      猜你喜欢
      • 2020-02-12
      • 2013-11-30
      • 2013-10-23
      • 2014-09-02
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多