2015-11-14 26 views
1

我正在創建一個網站,我想要設置聯繫人電子郵件表單。類似這樣的:contact email form image在php中聯繫電子郵件表格

我明白這段代碼會這麼做嗎? 但是,當我點擊提交按鈕什麼也沒有發生。 我從來沒有使用PHP之前,所以我不知道我做錯了什麼。

<?php 
 
if(isset($_POST['submit'])){ 
 
    $to = "[email protected]"; // this is your Email address 
 
    $from = $_POST['email']; // this is the sender's Email address 
 
    $first_name = $_POST['first_name']; 
 
    $subject = "Form submission"; 
 
    $subject2 = "Copy of your form submission"; 
 
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message']; 
 
    $message2 = "Here is a copy of your message " . $first_name . "\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 
 
    } 
 
?> 
 

 
<!DOCTYPE html> 
 
<head> 
 
<title>Form submission</title> 
 
</head> 
 
<style> 
 
#from{ 
 
\t font-weight: bold; 
 
\t font-family: Trajan Pro; 
 
\t font-size: 14px; 
 
\t color: #66441c; 
 
\t } 
 
.input{ 
 
\t outline: none; 
 
\t margin: 5px 0 10px 0; 
 
\t padding-left: 10px; 
 
\t width: 230px; 
 
\t height: 35px; 
 
\t font-family: Adobe Garamond Pro; 
 
\t font-size: 14px; 
 
\t color: #A4A4A4; 
 
\t border-radius: 5px; 
 
\t border: 1px solid #a37f4f; 
 
\t } 
 
textarea { 
 
\t padding-top: 10px; 
 
\t } \t 
 
#message{ 
 
\t outline: none; 
 
\t margin: 5px 0 10px 0; 
 
\t padding-left: 10px; 
 
\t width: 230px; 
 
\t height: 60px; 
 
\t font-family: Adobe Garamond Pro; 
 
\t font-size: 14px; 
 
\t color: #A4A4A4; 
 
\t border-radius: 5px; 
 
\t border: 1px solid #a37f4f; 
 
\t } \t 
 
#button{ 
 
\t margin-top: -10px; 
 
\t border: none; 
 
\t outline: none; 
 
\t border-radius: 5px; 
 
\t width: 230px; 
 
\t height: 35px; 
 
\t font-family: Trajan Pro; 
 
\t font-size: 14px; 
 
\t color: #fff; 
 
\t background-color: #a37f4f; 
 
\t } 
 
#button:hover { 
 
    background-color: #401b0f; 
 
    color: #a37f4f; 
 
} \t \t 
 
</style> 
 
<body> 
 

 
<form id="from" action="" method="post"> 
 
Name <input class="input" type="text" name="first_name"><br> 
 
Email <input class="input" type="text" name="email"><br> 
 
Message <br><textarea id="message" rows="5" name="message" cols="30"></textarea><br> 
 
<input id="button" type="submit" name="submit" value="Submit"> 
 
</form> 
 

 
</body> 
 
</html>

+0

沒有顯示成功消息,也沒有錯誤檢查或報告,所以如果失敗,您將不會收到錯誤消息。如果您收到電子郵件,唯一確認的方法就是。一旦你縮小了發生的事情,你可以嘗試各種各樣的事情。 – Tristan

回答

0

嘗試檢查電子郵件發送或沒有。

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

    $headers = "From:".$from; 
    $headers2 = "From:".$to; 
    $email1 = mail($to, $subject, $message, $headers); 
    $email2 = mail($from, $subject2, $message2, $headers2); // sends a copy of the message to the sender 
} 
if ($email1) {// checking if email 1 is sent 
    echo "Email 1 is sent"; 
} else { 
    echo "Email 1 is not sent"; 
} 
if ($email2) {//checking if email 2 is sent 
    echo "Email 2 is sent"; 
} else { 
    echo "Email 2 is not sent"; 
} ?> 

添加到您的表單屬性。 action="<?php echo $_SERVER['PHP_SELF']; ?>" 例如:<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

0

表單的actiononsubmit屬性是空白的,所以形式的信息從未在任何地方提交。你需要或者指定哪些頁面表單的內容發送到(使用action="...")或指定一個JavaScript函數(使用onsubmit="...")來執行,否則當您單擊Submit按鈕,什麼都不會發生。

0

我有類似的問題

form Tag

action="<?php echo $_SERVER['PHP_SELF']; ?>" 
0

使用爲什麼你用$last_name?請刪除它或爲姓添加一個新的文本框。

相關問題