gpt4 book ai didi

php - 表格提交和邮件发送

转载 作者:行者123 更新时间:2023-11-29 13:52:47 27 4
gpt4 key购买 nike

我用php制作了一个注册表单。该表单有提交者电子邮件地址字段。我希望在表单提交后,表单内容将通过提交者电子邮件地址和管理员电子邮件地址发送给表单提交者和管理员。提交者电子邮件地址将从提交者电子邮件地址字段中获取。管理员电子邮件地址是固定的。对于提交者headers=“来自:no-reply@eschool.com”消息正文与原样相同

对于管理员headers=“来自:$email”消息正文与原样相同

我尝试这样做:

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);

谢谢

最佳答案

你的代码很完美,你面临的问题是什么,请写下你的问题。为了您的方便,请在 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.";
}
?>

关于php - 表格提交和邮件发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16432874/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com