【发布时间】:2023-04-08 04:30:02
【问题描述】:
我有一个表单,接待员在其中输入访客信息、名字、电子邮件等,我想使用表单中输入的电子邮件地址向访客发送电子邮件。
我有 php 邮件功能,但它目前只发送给我手动指定的特定发件人。如何使此表单上的提交按钮根据电子邮件字段的内容发送电子邮件?
我认为我需要做这样的事情
<?php
$to = $row['email'];
$subject = 'Welcome ' . $row['first_name'] . ';
$message = 'You have been booked in';
$headers = 'From: noreply@blah.com' . "\r\n" .
'Reply-To: noreply@blah.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
我认为 $row[] 不正确,因为我想从表单中提取,而不是从表单输入的表格中提取。
这是表单页面:
//serve POST method, After successful insert, redirect to customers.php page.
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
//Mass Insert Data. Keep "name" attribute in html form same as column name in mysql table.
$data_to_store = filter_input_array(INPUT_POST);
//Insert timestamp
$db = getDbInstance();
$last_id = $db->insert ('tb_bookings', $data_to_store);
if($last_id)
{
$_SESSION['success'] = "Visitor signed in successfully!";
header('location: bookings.php');
exit();
}
}
//We are using same form for adding and editing. This is a create form so declare $edit = false.
$edit = false;
require_once('includes/admin-header.php');
?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h2 class="page-header">Manual Sign-in</h2>
</div>
</div>
<form class="form" action="" method="post" id="visitor_form" enctype="multipart/form-data">
<?php include_once('../forms/prebook_form.php'); ?>
</form>
</div>
这是形式:
<fieldset>
<div class="form-group">
<label for="f_name">First Name *</label>
<input type="text" name="first_name" value="<?php echo $edit ? $tb_bookings['first_name'] : ''; ?>" placeholder="First Name" class="form-control" required="required" id = "first_name" >
</div>
<div class="form-group">
<label for="l_name">Last name *</label>
<input type="text" name="last_name" value="<?php echo $edit ? $tb_bookings['last_name'] : ''; ?>" placeholder="Last Name" class="form-control" required="required" id="last_name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" value="<?php echo $edit ? $tb_bookings['email'] : ''; ?>" placeholder="E-Mail Address" class="form-control" id="email">
</div>
<div class="form-group">
<label>Visiting Date</label>
<input name="visiting_date" value="<?php echo $edit ? $tb_bookings['visiting_date'] : ''; ?>" placeholder="Visiting Date" class="form-control" type="date">
</div>
<div class="form-group">
<label>Visiting</label>
<input name="visiting" value="<?php echo $edit ? $tb_bookings['visiting_date'] : ''; ?>" placeholder="Who are they visiting?" class="form-control" id="visiting">
</div>
<div class="form-group text-center">
<label></label>
<button type="submit" class="btn btn-warning" >Save <span class="glyphicon glyphicon-send"></span></button>
</div>
</fieldset>
【问题讨论】:
-
我相信您正在从表单提交时寻找
$_POSTsuperglobal。或者也许你的$data_to_store变量是你通过过滤得到的。 -
“我如何在 PHP 中访问表单数据”确实是您应该能够自己阅读的内容。本网站不能替代学习基础知识和自行完成一些初学者教程。