2014-11-05 54 views
-1

我想做一個PHP代碼提交一些信息發送到我的私人電子郵件地址我正在尋找的代碼是通過電子郵件發送並提交。 =這是我的代碼:我需要通過什麼方式發送輸入類型。提交按鈕請

"<div class="form_settings"> 
      <p><span>Navn</span><input class="contact" type="text" name="your_name" value="" /></p> 
      <p><span>Email Addresse</span><input class="contact" type="text" name="your_email" value="" /></p> 
      <p><span>Besked</span><textarea class="contact textarea" rows="5" cols="50" name="your_message"></textarea></p> 
      <p style="padding-top: 15px"><span>&nbsp;</span><input class="submit" type="submit" name="contact_submitted" value="send"></p> 
      </div>" 

回答

0

插入此頁面上您的表單操作點(例如,如果你有,那麼你應該把這個代碼在send_message.php:

<?php 
    if (isset($_POST['your_name']) && isset($_POST['your_email']) && isset($_POST['your_message'])) { 
     if (!empty($_POST['your_name']) && !empty($_POST['your_email']) && isset($_POST['your_message'])) { 
      $to = "INSERT THE EMAIL ADDRESS YOU WANT TO SEND TO"; 
      $subject = "SUBJECT"; 
      $name = $_POST['your_name']; 
      $email = $_POST['your_email']; 
      $message = "$name sent you a message:" 
      $message .= "<br><br>" . $_POST['your_message']; 
      $headers = "MIME-Version: 1.0" . "\r\n"; 
      $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
      $headers .= 'From: ' . $email . "\r\n"; 

      if (mail($to,$subject,$message,$headers)) { 
       header('Location: confirmation.php'); 
      }; 
     }; 
    }; 
?> 

PS學習PHP需要時間,但值得的,youtube有很多好的視頻。

+0

我很喜歡PHP的新手,但很高興有一些幫助。謝謝你的回覆我的問題,如果我會提醒爲了讓用戶知道郵件已發送,我該怎麼辦? – Jgoldenlion 2014-11-05 11:52:06

+0

您可以使用其他頁面(例如我們e action =「confirmation.php」在

元素中。 在該頁面上,您可以添加一條說明已成功發送的消息。 – 2014-11-05 12:46:11

+0

或者您也可以更改: 郵件($ to,$ subject,$ message,$ headers); 對此: if(mail($ to,$ subject,$ message,$ headers)){ header('Location:confirmation.php'); }; 這比我寫的其他的更好,因爲如果郵件發送成功(郵件()返回true,它只會重定向)。 – 2014-11-05 12:48:15

相關問題