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


PHP: Emailing echo results

我正在完成一个已经工作了大约两周的项目。我的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,通过电子邮件发送到正确的地址以使表单可打印。这之前的代码是echo的PHP,正如@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);
?>

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

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

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

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

  4. 信息以电子邮件形式发送

审核表单[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页面,以便执行另一次审核

将您现在所称的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,因为上面的代码内置了电子邮件功能。

我希望这能有所帮助。

在不知道项目范围的情况下很难提供"答案",但您可能会发现这个函数在PHP中很有用:

$output = file_get_contents($url);

你总是可以在后面添加一些东西,所以如果上面的$url是一个响应结果的文件,你可以在末尾添加一些东西:

$output .= $signature

然后通过电子邮件将$output作为正文或其他内容发送给