dsfsw1233 2018-06-27 13:23
浏览 54

PHP Onsubmit发送电子邮件

I have a form where a receptionist enters a visitors information, first name, email etc and I want to send an email to the visitor using their email address entered in the form.

I have the php mail function working however it currently only sends to a specific sender that I manually specify. How do I make the submit button on this form send an email based on the contents of the email field?

I assume I need to do something like this

<?php
$to      = $row['email'];
$subject = 'Welcome ' . $row['first_name'] . ';
$message = 'You have been booked in';
$headers = 'From: noreply@blah.com' . "
" .
    'Reply-To: noreply@blah.com' . "
" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> 

I dont think the $row[] is correct as I want to pull from the form, not the table that the form is inputting into.

This is the form page:

//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>

And this is the form:

<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>
  • 写回答

1条回答 默认 最新

  • dongzong1866 2018-06-27 13:32
    关注

    maybe something like this...

    if (isset($_POST['submit'])) {
    
        $to = $_POST['email'];
        $name = $_POST['first_name'];
        $subject = 'Welcome ' . $name;
        $message = 'You have been booked in';
    $headers = 'From: noreply@blah.com' . "
    " .
        'Reply-To: noreply@blah.com' . "
    " .
        'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?