2016-02-12 31 views
-1

只是一個快速的(希望)...發送信息到數據庫以及郵件

我已經創建了一個登陸頁面,它也有一個聯繫表單。 我想將聯繫表格發送到我已成功完成的數據庫。但是,我想添加一個「謝謝」消息,表示他們已成功提交表單。

我希望能夠通過電子郵件的形式發送郵件,例如通知他們,讓他們知道誰和誰的註冊信息。

這是Process.php文件,因爲我相信這是我所需要的。

<?php 

    define('DB_NAME', 'cl54-the-acorn'); 
    define('DB_USER', 'cl54-the-acorn'); 
    define('DB_PASSWORD', '*******'); 
    define('DB_HOST', 'localhost'); 


    $link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 

    if (!$link) { 
     echo "Error: Unable to connect to MySQL." . PHP_EOL; 
     echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; 
     echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; 
     exit; 
    } 

    echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL; 
    echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL; 

    $query = "INSERT INTO users VALUES ('$_POST[forname]', '$_POST[surname]', '$_POST[email]', '$_POST[mobile]', '$_POST[telephone]', '$_POST[message]', '$_POST[title]')"; 
    $result = mysqli_query($link, $query); 
    if (false===$result) { 
     printf("There has been an error please contact the server admin: %s\n", mysqli_error($link)); 
    } 
    else { 
     header("Location: http://the-acorns.com/"); 
     die(); 
    } 

    mysqli_close($link); 

    ?> 
+0

不使用你的else條件的工作郵件功能? – codisfy

+0

無法在任何地方看到您的郵件功能。 –

+0

這就是我需要添加的 – Phil

回答

0
 <?php 
    if(isset($_POST['submit'])){ 
     $to = "[email protected]"; // this is your Email address 
     $from = $_POST['email']; // this is the sender's Email address 
     $forname = $_POST['forname']; 
     $last_name = $_POST['surname']; 
     $subject = "Form submission"; 
     $message = $forname . " " . $surname . " wrote the following:" . "\n\n" . $_POST['message']; 
     $message2 = "Here is a copy of your message " . $forname . "\n\n" . $_POST['message']; 

     $headers = "From:" . $from; 
     $headers2 = "From:" . $to; 
     mail($to,$subject,$message,$headers); 
     mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender 
     echo "Mail Sent. Thank you " . $forname . ", we will contact you shortly."; 
     // You can also use header('Location: thank_you.php'); to redirect to another page. 
     // You cannot use header and echo together. It's one or the other. 
     } 
    ?> 
0

請else部分添加郵件功能。見php:mail function

例子:

$message="your customized message or whatever you want to send"; 
mail('$_POST[email]', 'Thank you for your feedback', $message); 
+0

對不起,你可以告訴我這是怎麼做的請 – Phil

+0

@Phil只看例子 – geeksal

相關問題