2016-02-12 50 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

相关问题