我正在創建一個網站,我想要設置聯繫人電子郵件表單。類似這樣的: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>
沒有顯示成功消息,也沒有錯誤檢查或報告,所以如果失敗,您將不會收到錯誤消息。如果您收到電子郵件,唯一確認的方法就是。一旦你縮小了發生的事情,你可以嘗試各種各樣的事情。 – Tristan