I want my form to add the new user to the database and email the new user details to someone. In my code you can see my attempts but it all fails the page wont even open with my attempt in it.
When the user clicks submit the form must add the new user to the database ( that code is working ) and email the new users details to someone.
<?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: " . "
" . "Name : " . $name . " " . "
" . "Email: " . $email . " " . "
" . "Department: " . $department . " " . "
" . "Extension: " . $extension . " " . "
" . "Cellphone: " . $cellphone . " " . "
"
$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");
}
}
}
?>