dongruoqiong9017 2016-07-04 10:56
浏览 16

表单提交数据和电子邮件结果

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");
            }
    }
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line