2015-10-17 86 views
-1

我創建了一個名爲'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> 
+0

你在localhost上還是在機器上運行這個設置? – Akshay

+0

使用one.com作爲我的服務器。 – methhead

+0

爲什麼你沒有設置'$ to =「[email protected]」;'? –

回答

0

你沒有任何有name ='submit'的輸入。 將這件商品加入購物車。

<input type="hidden" name="submit">

由於您的代碼顯示爲if(isset($_POST['submit'])),但$_POST['submit']未設置。

0

如果你想在本地主機上發送電子郵件,您應該設置電子郵件設置在php.ini取決於您的ISP。

這是爲我的國家(克羅地亞)ISP名稱(T-COM):

ini_set("SMTP", "mail.t-com.hr"); 
ini_set("smtp_port", "25"); 

$message = ""; 

if(mail('[email protected]', 'title', $message, "From: [email protected]")) 
{ 
    echo 'sent succesfull'; 
} 

,但是這取決於ISP和國家。

PS.ini_set「(」SMTP「,」mail.t-com.hr「);」和「ini_set(」smtp_port「,」25「);」可以從代碼調用或在php.ini中設置

+0

如果你有足夠的聲望,請在評論框中回答這種類型的內容。 –

+0

看看我編輯的答案 – fico7489

0

爲什麼使用標準的vanilla php郵件函數()。而是切換到Mailgun或phpmailer,您可以自動加載到您的代碼併發送郵件。它的更快和更可靠的郵件()功能。並以使用mailgun爲例;您可以通過網站查看日誌,看看您的郵件是否已發送100%。祝你好運