私はかなりPHPに新しいです、私は電子メールの提出(ニュースレター)フォーム作業をしようとしています。HTML/PHPニュースレターフォーム
<form class="form-inline" action="mail-handler.php" method="post">
<div class="col-sm-5 col-sm-offset-2 col-md-4 col-md-offset-3">
<label class="sr-only" for="email">Email</label>
<input type="text" id="email" placeholder="Your email address.." />
</div>
<div class="col-sm-3 col-md-2">
<input type="submit" name="submit" class="btn btn-submit" value="Submit">
</div>
</form>
そして、それのために、私は次のコードでメールhandler.phpファイルを作成しました:
<?php
$to = "[email protected]"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$subject = "Form submission";
$subject2 = "You have just subscribed to the Plantsnap newsletter!";
$message = $from . " just subscribed for your Newsletter" ;
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
//Headers
$headers .= "From: <".$from. ">";
$headers2 = "From:" . $to;
if(isset($_POST['submit'])){
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "You have subscribed to our newsletter. Thank you, we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
} ?>
問題: は、私は次のHTMLフォーム持ってIを押すと を提出ボタンを押すと、それは私のアドレスに電子メールを送信しますが、私は次の電子メール受け取る:
から: へ:[email protected] DATをE:木、2017年3月16日12:23 被写体に:フォームの提出 暗号化:標準(TLS)は、あなたが見ることができるように
詳細はこちらから:フィールド$ことを意味し、空でありますfrom = $ _POST ['email']は入力フィールドに何を入力してもNULLを返します。
私は間違っていますか?
また、私はもう一つ質問があります:どのように私は、フォームの送信からのメッセージは、代わりに "/メールhandler.phpをリンクし、エコーために私をリダイレクトする、フォームの下に小さなツールチップとして表示されます
することができますがあなたはニュースレターを購読しました。ありがとうございます、まもなくご連絡させていただきます。
ありがとうございます!
、あなたは '名=「」'ではなく 'IDを=「」'必要 - エラー報告とあなたをオンにします」 d "Undefined index"のエラーが発生しました – Epodax
[HTML Form POSTがnullの可能性のある重複](http://stackoverflow.com/questions/21450748/html-form-post-is-null) – ConquerorsHaki