用 php 代码检查此 html。这个怎么做?我是初学者。
我正在制作一个带有下拉菜单的联系表单,用于选择特定医生的电子邮件地址。我正在使用模板工作,并且在 PHP 方面没有太多经验。
HTML 代码:
<div class="col-md-6 form-group mb-5"> <label for="package" >Package *</label> <select id="package" class="form-control" name="package"> <option class="form-control" disabled selected value> -- select an option -- </option> <option value="value1">pkg1</option> <option value="value2">pkg2</option> <option value="value3">pkg3</option> <option value="value4">pkg4</option> <option value="value5">pkg5</option> <option value="value6">pkg6</option> <option value="value7">pkg7</option> </select> </div>
PHP 代码:
<?php // Get data from form $name = $_POST['name']; $email= $_POST['email']; $message= $_POST['message']; $package = $_POST['package']; switch ($package) { case 'value1': $mail_to = 'your Visiting1 email'; break; case 'value2': $mail_to = 'your Visiting2 email'; break; case 'value3': $mail_to = 'your Visiting3 email'; break; } $to = "mail@mail.com"; $subject="This message came from dc-ec.in Contact page"; // The following text will be sent // Name = user entered name // Email = user entered email // Message = user entered message $txt ="Name = ". $name . "\r\n Email = " . $email . "\r\n Subject = " . $mail_to . "\r\n Subject = " . $package . "\r\n Message =" . $message; $headers = "From: no-reply@domain.in" . "\r\n" . "CC: name@domain.in"; if($email != NULL) { mail($to, $subject, $txt, $headers); } // Redirect to header("Location:contact.html"); ?>
添加如下所示的 If 条件,以便根据下拉列表选择发送邮件