私はそれが簡単だろうと思っていました(私は知っています)ので、このサイトでPHPの電子メールフォームの指示に従いました:http://www.html-form-guide.com/email-form/dreamweaver-email-form.html私はDreamweaverのインターフェイスを手助けして、私はスクリプトを必要としました。私は必要なフォームに簡単なフォームを適合させる方法を知っていました(または思っていました)。新参者は、壊れたPHP電子メールフォームを修正する方法を知る必要があります
問題の形式は、次のURLで見ることができる:http://nineinchbride.com/SuitedForWar_BookTwo_PreOrderForm.php
次のように、それが現在のページに存在するコードは次のとおりです。
<form id="PreOrder_Book_2" name="PreOrder_Book_2" method="post" action="">
<p>Your Name:
<input type="text" name="CustomerName" id="CustomerName" />
</p>
<p>Your Email:
<input type="text" name="CustomerEmail" id="CustomerEmail" />
</p>
<p>
<input type="checkbox" name="NotifyPaperback" id="NotifyPaperback" />
Notify me when paperback is available.</p>
<p>
<input type="checkbox" name="Notify_eBook" id="Notify_eBook" />
Notify me when eBook is available.</p>
<p>Desired eBook Format:</p>
<p>
<label>
<input type="radio" name="eBookFormats" value=".mobi" id="eBookFormats_0" />
.mobi (Kindle)</label>
<br />
<label>
<input type="radio" name="eBookFormats" value=".epub" id="eBookFormats_1" />
.epub (Nook/Ipad/Sony/Kobo)</label>
<br />
<label>
<input type="radio" name="eBookFormats" value=".pdf" id="eBookFormats_2" />
.pdf (All readers)</label>
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
<br />
</p>
</form><script>
function validateForm()
{
var name=document.forms["PreOrder_Book_2"]["CustomerName"].value;
if (name==null || name=="")
{
alert("Name cannot be left blank.");
return false;
}
var z=document.forms["PreOrder_Book_2"]["CustomerEmail"].value;
if (z==null || z=="")
{
alert("Please enter your email.");
return false;
}
}
</script>
<script><?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['CustomerName'];
$visitor_email = $_POST['CustomerEmail'];
$message = $_POST['NotifyPaperback'];
$message = $_POST['Notify_eBook'];
$message = $_POST['eBookFormats'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
$email_from = '[email protected]';//<== Put your email address here
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"email address: $visitor_email\n".
"Here is the message:\n $message".
$to = "[email protected]";//<== Put your email address here
$headers = "From: $email_from \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: http://nineinchbride.com');
?></script>
私は私の方法を知っている間ことを心に留めておいてください。コードをちょっと(ちょっとしたことに適応し、一貫性などのために命名を調整するのに十分です)、私はプログラマーではありませんそれ自体はです。
アップデート1:
さて、私はここに進歩しています。私はPHPに次の変更を加えました:
$name = $_POST['CustomerName'];
$visitor_email = $_POST['CustomerEmail'];
$message1 = $_POST['NotifyPaperback'];
$message2 = $_POST['Notify_eBook'];
$message3 = $_POST['eBookFormats'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
$email_from = '[email protected]';//<== Put your email address here
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"email address: $visitor_email\n".
"Notify When Paperback Is Available: $message1\n".
"Notify When eBook Is Available: $message2\n".
"My eBook Format Is: $message3\n".
さらに、私はすべてのフォームデータを取得しています。
しかし、妥当性検査のどれも動作していません。成功した投稿の後にリダイレクトすることもできません。どのようなアイデアがあるの?
アップデート2:
うわー、検証問題解決、あなたの駆虫に感謝!私はちょうど私が前にいた、そして今、フロントエンドの検証が動作している送信ボタンの代わりに、フォーム自体に
<input type="button" name="button" id="button" value="Submit" onclick="return validateForm();"/>
を追加しました。すばらしいです!
今、フォーム自体はもう送信されません!私は何を間違えたのですか?
問題は何ですか?電子メールを送信しない? – Poria
私は「メール」を受け取っています。それは問題ではありません。問題は、チェックボックスデータおよび/またはラジオボタンデータが通過していないことです。私が得るのは、送信者の名前と電子メールだけです。ありがとう。 – user6318597
私は問題がここにあると思います: $ message = $ _POST ['NotifyPaperback']; $ message = $ _POST ['Notify_eBook']; $ message = $ _POST ['eBookFormats']; しかし、私はそれを修正する方法がわかりません。 – user6318597