我希望我的表单将新用户添加到数据库,并将新用户详细信息通过电子邮件发送给某人。在我的代码中你可以看到我的尝试但是这一切都无法通过我的尝试打开页面。
当用户点击提交时,表单必须将新用户添加到数据库(该代码正在运行),并将新用户详细信息通过电子邮件发送给某人。
<?php
require_once"connection.php";
?>
<!DOCTYPE html>
<html>
<head>
<?php include"includes/head.inc"; ?>
<script>tinymce.init({selector:'textarea'});</script>
</head>
<body>
<div class="wrapper">
<!-- header section -->
<div class="header">
<div class="headerContent"><h1>CONTACT LIST</h1></div>
</div>
<!-- content section -->
<div class="content">
<div><h1>Create New Contact</h1></div>
<hr>
<div class="contact">
<div class="contact_insert">
<form action="insert_contact.php" method="post">
<table style="float:left" width="50%">
<tr>
<td>Name:</td>
<td><input type="text" name="name" placeholder="name" size="40%"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" placeholder="email" size="40%"></td>
</tr>
<tr>
<td>Department:</td>
<td><input type="text" name="department" placeholder="department" size="40%"></td>
</tr>
<tr>
<td>Extension Number:</td>
<td><input type="text" name="extension" placeholder="extension" size="40%"></td>
</tr>
<tr>
<td>Cellphone:</td>
<td><input type="text" name="cellphone" placeholder="cellphone" size="40%"></td>
</tr>
</table>
<div class="clear"></div>
<input class="insert_contact_button" type="submit" name="submit" value="Insert Contact">
<a href="index.php"><input class="cancel_contact_button" type="button" value="Cancel"></a>
</form>
</div>
<div class="clear"></div>
</div>
</div>
</body>
</html>
<?php
if (isset($_POST['submit'])) {
\\adding the user to the database works perfectly
$name = $_POST['name'];
$email = $_POST['email'];
$department = $_POST['department'];
$extension = $_POST['extension'];
$cellphone = $_POST['cellphone'];
\\ Heres my attempt
$to = "test@test.co.za";
$from = "ExtensionList@test.co.za";
$subject = "New Staff Added To Extension List";
$subject2 = "Copy of your form submission";
$message = . "New Staff: " . "\n\n" . "Name : " . $name . " " . "\n\n" . "Email: " . $email . " " . "\n\n" . "Department: " . $department . " " . "\n\n" . "Extension: " . $extension . " " . "\n\n" . "Cellphone: " . $cellphone . " " . "\n\n"
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$insert_contact = "insert into contacts (name, email, department, extension, cellphone) values ('$name', '$email', '$department', '$extension', '$cellphone')";
$sql_insert_contact = $conn->query($insert_contact);
if ($sql_insert_contact == true) {
header("Location: index.php");
}
}
}
?>