PHP:通过电子邮件发送回显结果

时间:2013-08-13 02:55:20

标签: php

我正在做一个我已经工作了大约两个星期的项目的主页。我的HTML表单是在PHP中完全和功能完全兼容的。目前,在提交表格后,它回显了结果。在这一点上,我不知道下一步该去哪里。

我希望能够从该页面获取信息,并添加数字数字签名(很像PIN),并使用PHP将最终结果提交给电子邮件。

我可以分开做两个。 IE - 我可以创建一个表单来回显结果,我可以创建一个立即通过电子邮件发送结果的表单,但我不明白如何相互结合使用它们。

如何在添加数字签名的同时将表单的回显结果作为电子邮件提交?

(因为我没有提供代码,因为我对PHP很新,我不希望有人为我这个,但我很难通过谷歌搜索找到相关信息,所以即使指点我在正确的方向将是非常有帮助的。)

由于

现在我知道的更好。所有代码:

HTML

<form action="echo_form_email.php" method="GET">

<p>
<div id="cheddar">Cashier: <input id="cashier" name="cashier" type="text"></div> 
</p>

<P>
<div id="q">Did the cashier front the register?</div>
<div id="radio1"><input type="checkbox" name="front_register" value="Yes">Yes</div> 
    <div id="radio2"><input type="checkbox" name="front_register" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="front_register" value="N/A">N/A</div>
</p>

<p>
<div id="q">Genuinely greet customer with eye contact?</div>
<div id="radio1"><input type="checkbox" name="greets" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="greets" value="No">No</div> 
</p>

<p>
<div id="q">Scan/unload B.O.B. (If no bagger)</div>
<div id="radio1"><input type="checkbox" name="scan_bob" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="scan_bob" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="scan_bob" value="N/A">N/A</div>
</p>

<p>
<div id="q">Carry conversation around product in basket or genuine conversation?</div>
<div id="radio1"><input type="checkbox" name="conversation" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="conversation" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="conversation" value="N/A">N/A</div>
</p>

<p>
<div id="q">Offer buddy bucks to parent at beginning of order?</div>
<div id="radio1"><input type="checkbox" name="buddy" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="buddy" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="buddy" value="N/A">N/A</div> 
</p>

<p>
<div id="q">Avoid side conversations?</div>
<div id="radio1"><input type="checkbox" name="side_conversation" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="side_conversation" value="No">No</div> 
</p>

<p>
<div id="q">Point out and circle savings?</div>
<div id="radio1"><input type="checkbox" name="savings" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="savings" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="savings" value="N/A">N/A</div>
</p>

<p>
<div id="q">Offer carryout (if no bagger)?</div>
<div id="radio1"><input type="checkbox" name="carry_out" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="carry_out" value="No">No</div> 
<div id="radio3"><input type="checkbox" name="carry_out" value="N/A">N/A</div>
</p>

<p>
<div id="q">Give a genuine "thank you"?</div>
<div id="radio1"><input type="checkbox" name="thanks" value="Yes">Yes</div> 
<div id="radio2"><input type="checkbox" name="thanks" value="No">No</div> 
</p>

<p>
<div id="cheddar">Digital Signature</div>
<div id="cheddar"><input type="tel" name="sign1" placeholder="Peoplesoft ID"></div>
</p>

<p>
<div id="auditingasm">ASM performing audit: <br />
<select name="asm">
<option value="John Doe">John Doe</option>
<option value="Jane Doe">Jane Doe</option>
<option value="Little Doe">Little Doe</option>
<option value="Big Doe">Big Doe</option>
</select></div>
</p>

<br />
<input type="submit" value="submit" name="submit">
<input id="reset" type="reset">
</form>

PHP表单echo

<?PHP
if (! empty($_GET['cashier'])){
   echo 'Cashier receiving audit: ' . $_GET['cashier'];
}
echo "<br />";
if (! empty($_GET['asm'])){
   echo 'ASM performing audit: ' . $_GET['asm'];
}
echo "<br /><Br />";
if (! empty($_GET['front_register'])){
   echo 'Did cashier front the register? ' . $_GET['front_register'];
}
echo "<br />";
if (! empty($_GET['greets'])){
   echo 'Greet customer with eye contact? ' . $_GET['greets'];
}
echo "<br />";
if (! empty($_GET['scan_bob'])){
   echo 'Scan/Unload BOB (if no bagger) ' . $_GET['scan_bob'];
}
echo "<br />";
if (! empty($_GET['conversation'])){
   echo 'Conversation about groceries, or other genuine conversation? ' .     $_GET['conversation'];
}
echo "<br />";
if (! empty($_GET['buddy'])){
   echo 'Offer Buddy bucks to parent at beginning of order? ' . $_GET['buddy'];
}
echo "<br />";
if (! empty($_GET['side_conversation'])){
   echo 'No side conversations? ' . $_GET['side_conversation'];
}
echo "<br />";
if (! empty($_GET['savings'])){
   echo 'Cashier pointed to and circled savings? ' . $_GET['savings'];
}
echo "<br />";
if (! empty($_GET['carry_out'])){
   echo 'Offered carry out (if no bagger) ' . $_GET['carry_out'];
}
echo "<br />";
if (! empty($_GET['thanks'])){
   echo 'Genuine "thank you?" ' . $_GET['thanks'];
}
echo "<br /><Br />";
if (! empty($_GET['sign1'])){
   echo 'Digital Signature: ' . $_GET['sign1'];
}
?>

PHP表单电子邮件

这是附加到表单的原始php,通过电子邮件发送到正确的地址,使表单可打印。这个代码之前的代码是PHP for echo,正如@Death今天早些时候在另一个论坛上发布的那样。
<?
//---------------
// Cashier Audit
//---------------
$msg .= "Cashier being audited: ".$_POST["cashier"]."";
$msg .= "\n\nFront the register? $front_register\n";
$msg .= "Greet customer with eye contact? $greets\n";
$msg .= "Scan/Unload BOB (if no bagger) $scan_bob\n";
$msg .= "Conversation about groceries, or other genuine conversation? $conversation\n";
$msg .= "Offer Buddy bucks to parent at beginning of order? $buddy\n";
$msg .= "No Side Conversations? $side_conversation\n";
$msg .= "Cashier pointed to and circled savings? $savings\n";
$msg .= "Offered carry out (if no bagger)? $carry_out\n";
$msg .= "Genuine Thank You? $thanks\n\n";
$msg .= "**************************************************************\n";
$msg .= "\n\n\nCashier signature:__________________________";
$msg .= "\n                             $cashier";
$msg .= "\n\n\n\n\nASM signature:__________________________";
$msg .= "\n                         $asm";

//-----------------
// Signature Lines
//-----------------
.= $checkbox=$_POST['checkbox'];
.= $asm = $_POST['asm'];

$to = "email@address.com";
$from = "other@email.com";
$subject = "Service Audit";
$mailheaders = "From: \"$asm\" <$from> . \n";
//$mailheaders .= "Reply-To: $from\n\n";

mail($to, $subject, $msg, $mailheaders);

?>

2 个答案:

答案 0 :(得分:0)

很难在不知道项目范围的情况下提供“答案”,但您可能会发现此功能在PHP中很有用:

$output = file_get_contents($url);

你总是可以在后面添加内容,所以如果上面的$url是回显结果的文件,你可以添加一些内容,如:

$output .= $signature

然后只需将$ output作为正文或不是

发送电子邮件

答案 1 :(得分:0)

如果我理解正确,您有一个HTML表单,并希望:

  1. 在HTML / PHP表单上审核员工(audit.php

  2. 将审核结果发布到另一个PHP页面/表单(audit_confirm.php

  3. 员工在audit_confirm.php上输入他们的ID,然后有人点击“提交”

  4. 信息以电子邮件

  5. 发送

    审核表格[audit.php]

    您的第一页/表单将数据发布到确认页面,因此将表单标记的操作属性更改为发布到audit_confirm.php,即

    <form action="audit_confirm.php" method="post">
    <!-- all your existing form data-->
    </form>
    

    审核确认表[audit_confirm.php]

    audit_confirm.php上,您将创建以下逻辑:

    1. 显示审核结果
    2. 提供一个确认表单,其中包含一个文本框,可让员工输入他们的ID
    3. 将此信息发布到同一页面并捕获POST数据(隐藏的表单元素可用于分割表单逻辑流程)
    4. 发送包含审核数据的电子邮件
    5. 重定向到您的audit.php页面,以便执行其他审核
    6. 用以下内容替换现在称为PHP Form Echo的内容:

      <?php
      
          switch(true)
          {
              case ($_POST['employee_id_confirm'] == true):
      
                  //---------------
                  // Cashier Audit
                  //---------------
                  $msg .= "Cashier being audited: ".$_POST['cashier']."";
                  $msg .= "\n\nFront the register? ".$_POST['front_register']."\n";
                  $msg .= "Greet customer with eye contact? ".$_POST['greets']."\n";
                  $msg .= "Scan/Unload BOB (if no bagger) ".$_POST['scan_bob']."\n";
                  $msg .= "Conversation about groceries, or other genuine conversation? ".$_POST['conversation']."\n";
                  $msg .= "Offer Buddy bucks to parent at beginning of order? ".$_POST['buddy']."\n";
                  $msg .= "No Side Conversations? ".$_POST['side_conversation']."\n";
                  $msg .= "Cashier pointed to and circled savings? ".$_POST['savings']."\n";
                  $msg .= "Offered carry out (if no bagger)? ".$_POST['carry_out']."\n";
                  $msg .= "Genuine Thank You? ".$_POST['thanks']."\n\n";
                  $msg .= "**************************************************************\n\n\n\n\n";
                  $msg .= "Cashier signature:        ".$signature."\n";
                  $msg .= "                     _______________________________";
                  $msg .= "\n                     $cashier";
                  $msg .= "\n\n\n\n\n";
                  $msg .= "ASM signature:            ".$asm."\n";
                  $msg .= "                     ________________________________";
                  $msg .= "\n                         $asm";
      
                  $to = "email@address.com";
                  $from = "other@email.com";
                  $subject = "Service Audit";
                  $mailheaders = "From: \"".$asm."\" <".$from.">\r\n".
                  "Reply-To: noreply@yourdomain.com\r\n".
                  "X-Mailer: PHP/". phpversion();
                  mail($to, $subject, $msg, $mailheaders);
      
                  //redirect to audit.php
                  header("Location:audit.php");
                  exit();
                  break;
          }
      
          //form data from audit.php
          $get_data_meta_arr = array(
              'cashier' => 'Cashier receiving audit:',
              'asm' => 'ASM performing audit:',
              'front_register' => 'Did cashier front the register?',
              'greets' => 'Greet customer with eye contact?',
              'scan_bob' => 'Scan/Unload BOB (if no bagger)',
              'conversation' => 'Conversation about groceries, or other genuine conversation?',
              'buddy' => 'Offer Buddy bucks to parent at beginning of order?',
              'side_conversation' => 'No side conversations?',
              'savings' => 'Cashier pointed to and circled savings?',
              'carry_out' => 'Offered carry out (if no bagger)',
              'thanks' => 'Genuine "thank you?"'  
          );
      
      ?>
      <html>
      <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <title>Info Confirm</title>
      </head>
      <body>
          <div id="view-info">
              <h2>Audit Confirmation</h2>
          </div>
          <div id="form-confirm">
              <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                  <div class="field-hidden">
                      <input type="hidden" name="employee_id_confirm" value="true">                    
                  </div>
                  <div class="echo">
                      <?php
                      foreach($get_data_meta_arr as $key => $value)
                      {
                          $audit_question_str = $value;           //the audit question
                          $audit_result_str = $_GET[$key];        //the audit result              
                      ?>
                      <p><?php echo $audit_question_str.': '.$audit_result_str; ?></p>
                      <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $audit_result_str; ?>">
                      <?php
                      }
                      ?>
                  </div>
                  <div class="field">
                      <label for="employee_id">Employee ID</label>
                      <input id="employee_id" type="text" name="signature" maxlength="40">
                  </div>
                  <div class="action">
                      <input type="submit" value="Confirm">
                  </div>
              </form>
          </div>
      </body>
      </html>
      

      您可以取消PHP Form Email,因为上面的代码内置了电子邮件消息功能。

      我希望这会有所帮助。