2016-04-30 7 views
0

私は以下のコードを持つPHPファイルを持っています。私は提出したときにエラーが発生しているようです。このPHPフォームのフォームデータをメールに送信するにはどうすればよいですか?

エラーはPHPコード内のエラーページへのリダイレクトに過ぎず、エラーを引き起こす原因として「Your Name」を特定して参照していますが、解決する方法はありません。

PHPコードはここです|

<?php 
/* Set e-mail recipient */ 
$myemail = "[email protected]"; 

/* Check all form inputs using check_input function */ 
$name = check_input($_POST['inputName'], "Your Name"); 
$email = check_input($_POST['inputEmail'], "Your E-mail Address"); 
$subject = check_input($_POST['inputSubject'], "Message Subject"); 
$message = check_input($_POST['inputMessage'], "Your Message"); 

/* If e-mail is not valid show error message */ 
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) 
{ 
show_error("Invalid e-mail address"); 
} 
/* Let's prepare the message for the e-mail, but might not work for drop down subject...just try */ 

$subject = "Someone has sent you a message"; 

$message = " 

Someone has sent you a message using your contact form: 

Name: $name 
Email: $email 
Subject: $subject 

Message: 
$message 

"; 

/* Send the message using mail() function */ 
mail($myemail, $subject, $message); 

/* Redirect visitor to the thank you page */ 
header('Location: http://www.address.com/sucesssubmit.html'); 
exit(); 

/* Functions we used */ 
function check_input($data, $problem='') 
{ 
$data = trim($data); 
$data = stripslashes($data); 
$data = htmlspecialchars($data); 
if ($problem && strlen($data) == 0) 
{ 
show_error($problem); 
} 
return $data; 
} 

function show_error($myError) 
{ 
?> 
<html> 
<body> 

<p>Please correct the following error:</p> 
<strong><?php echo $myError; ?></strong> 
<p>Hit the back button and try again</p> 

</body> 
</html> 
<?php 
exit(); 
} 
?> 

フォームは、ここでは、入力の名前で

<form role="form" id="contact-form" method="post" action="send_form_email.php"> 
         <div class="form-group"> 
          <label for="name">Your Name</label> 
          <input type="text" name="name" class="form-control" id="name" /> 
         </div> 
         <div class="form-group"> 
          <label for="email">Email address</label> 
          <input type="email" name="email" class="form-control" id="email" /> 
         </div> 
         <div class="form-group"> 
          <label for="phone">Phone</label> 
          <input type="text" name="phone" class="form-control" id="phone" /> 
         </div> 
         <div class="form-group"> 
          <label for="message">Your message</label> 
          <textarea name="message" class="form-control" id="message" rows="6"></textarea> 
         </div> 
         <div class="submit"> 
          <button type="submit" class="button button-small" value="Email us" id="btnContactUs" /> 
         </div> 
</form> 
+0

。したがって、あなたのフォームのname属性を修正してください。 –

+0

投稿は私のHTMLに 'for'か 'name'か 'id'を使用しますか? –

+0

投稿は常に 'name'で使用されます。 –

答えて

0

アクセスの$ _POSTである:あなたのポスト変数は、あなたのname属性と一致しない

/* Check all form inputs using check_input function */ 
$name = check_input($_POST['name'], "Your Name"); 
$email = check_input($_POST['email'], "Your E-mail Address"); 
$subject = check_input($_POST['inputSubject'], "Message Subject"); // subject is not anymore in html 
$message = check_input($_POST['message'], "Your Message"); 
+0

多くのありがとう。私はhtmlで「電話」の件名を入れ替えるつもりだった。 上記のコードを参照している人は誰でも、「Subject」はHTMLには存在せず、「Phone」はPHPには含まれていないことに注意してください。彼らは交換される予定だった。 –

+0

ok ...このソリューションを試してみてください... –

関連する問題