我創建了一個名爲'name','email','mobile','message'的輸入的HTML表單。PHP窗體自動發送電子郵件
在我的HTML中我已經使用;
<form action='form_script.php' method='post'>
這將(在提交時)發送到我的form_script.php在我的PHP 應該執行。
form_script.php
我已經然後創建了應該得到的形式輸入和發送電子郵件至「[email protected]」這個PHP腳本。
問題是,電子郵件沒有被髮送。我檢查了我的PHP腳本無數次,我似乎無法找到任何問題,這就是爲什麼我在這裏發佈了第二個意見。
if(isset($_POST['submit'])){
$to = "[email protected]"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$subject = $_POST['subject'];
$subject2 = "Copy of your form submission";
$message = "Name: " .$name . "\n\n mobile number: " . $mobile . ".\n\n Message:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $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
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
在此先感謝您的時間。 山姆
HTML表單
<table style='width:100%'>
<form action='form_script.php' method='post'>
<tr>
<th> <input type='text' required placeholder='Name' name='name' /> </th> <th> <input type='text' required placeholder='Email' name='email' /> </th>
</tr>
<tr>
<th> <input type='text' required placeholder='Mobile' name='mobile' /> </th> <th> <input type='text' required placeholder='Subject' name='subject' /> </th>
</tr>
<tr>
<th colspan='2'><textarea required placeholder='Message' name='message' ></textarea></th>
</tr>
<tr>
<th><input id='send_form' type='submit' /> </th>
</tr>
</form>
</table>
你在localhost上還是在機器上運行這個設置? – Akshay
使用one.com作爲我的服務器。 – methhead
爲什麼你沒有設置'$ to =「[email protected]」;'? –