表单提交和邮件发送

时间:2013-05-08 04:49:07

标签: php mysql

我已经通过php制作了一份注册表格。该表格有提交者的电子邮件地址字段。我想在表格提交后,表格内容将通过提交者的电子邮件地址和管理员电子邮件地址发送给表格提交者和管理员。提交者电子邮件地址将来自提交者电子邮件地址字段.Admin电子邮件地址是固定的。 对于提交者 headers =“from:no-reply@eschool.com” messagebody与它相同

对于管理员 headers =“from:$ email” messagebody与它相同

我试着这样做:

Html代码:

<form action="action.php" method="post">
    <table>
        <tr>
            <td>Name</td>
            <td>:</td>
            <td><input type="text" name="name" width="400" /></td>
        </tr>
        <tr>
            <td>Address</td>
            <td>:</td>
            <td><input type="text" name="address" width="400" /></td>
        </tr>
        <tr>
            <td>Email</td>
            <td>:</td>
            <td><input type="text" name="email" width="400" /></td>
        </tr>
        <tr>
            <td>Password</td>
            <td rowspan="2">&nbsp;</td>
            <td>
                <p><input type="text" name="pass" width="400" /></p>
                <p>&nbsp;</p>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="insert" value="Insert" /></td>
        </tr>
    </table>

    <input type="submit" value="submit" />
</form>

action.php的

$name    = $_POST["name"];
$address = $_POST["address"];
$email   = $_POST["email"];

$password = $_POST['pass'];
$subject  = "Thank you for your registration.";
$admin    = "info@editor.com";

$to = $email . "," . $admin;

$email_message .= "Name: ". $name."\n";
$email_message .= "Address: ".$address."\n";
$email_message .= "Email: ".$email."\n";
$email_message .= "password: ".$password."\n";

$headers  = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/plain;charset=UTF-8;" . "\n";
$headers .= "content-Transfer-encoding: 8bit" ."\n";
$headers .= "From: no-reply@eschool.com ". "\n";

mail($to, $subject, $email_message, $headers);

由于

2 个答案:

答案 0 :(得分:1)

你的代码很完美,你面临的问题是什么,请写下你的问题。 为方便起见,在action.php中进行以下更改:

<?php
   $name    = $_POST["name"];
   $address = $_POST["address"];
   $email   = $_POST["email"];
   $password = $_POST['pass'];
   $subject  = "Thank you for your registration.";
   $admin    = "info@editor.com";
   //$to = $email  $admin;
   $email_message = '';

   $email_message .= "Name: ". $name."\n";

   $email_message .= "Address: ".$address."\n";

   $email_message .= "Email: ".$email."\n";

   $email_message .= "password: ".$password."\n";


   $headers1  = 'MIME-Version: 1.0' . "\r\n";
   $headers1 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";   
   $headers1 .= "From: no-reply@eschool.com ". "\n";

   $headers2  = 'MIME-Version: 1.0' . "\r\n";
   $headers2 .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";   
   $headers2 .= "From: ". $email . "\n"; 

   if(@mail( $email, $subject, $email_message  , $headers1 )) {
     @mail( $admin, $subject, $email_message  , $headers2 )          
    echo "Mail Sent.";
   } else {
    echo "Mail Not Sent.";
   }
?>   

答案 1 :(得分:0)

您只需制作两个不同版本的标题,然后执行mail(...)两次:

<?php

    $name    = $_POST["name"];
    $address = $_POST["address"];
    $email   = $_POST["email"];

    $password = $_POST['pass'];
    $subject  = "Thank you for your registration.";
    $admin    = "info@editor.com";


    $email_message = "Name: ".$name."\n";
    $email_message .= "Address: ".$address."\n";
    $email_message .= "Email: ".$email."\n";
    $email_message .= "password: ".$password."\n";

    $headers  = "MIME-Version: 1.0\n";
    $headers .= "Content-type:text/plain;charset=UTF-8;\n";
    $headers .= "content-Transfer-encoding: 8bit\n";

    $poster_headers = $headers . "From: no-reply@eschool.com\n";
    $admin_headers = $headers . "From: ".$email."\n";

    mail( $admin, $subject, $email_message, $admin_headers );
    mail( $email, $subject, $email_message, $poster_headers );
?>