<?php
$error="";$successMessage="";
if($_POST) {
$error="";
if(!$_POST("email"))
{
$error .="An email address is required<br>";
}//code works fine till here
//from here on the code gets printed on screen and is not working
if(!$_POST("content")){
$error.="The content field is required<br>";
}
if(!$_POST("subject")){
$error.="The subject is required<br>";
}
if ($_Post['email'] && filter_var($_POST("email"), FILTER_VALIDATE_EMAIL)===false) {
$error .="$email is not a valid email address. <br>";
}
if($error !==""){
$error='<div class="alert alert-danger" role="alert"><p><strong>There were error(s) in your form</strong></p>'. error . '</div>';
}
else
{
$emailTo="[email protected]";
$subject=$_POST("subject");
$content=$_POST("content");
$headers="From:"$_POST('email');
if(mail($emailTo,$subject,$content,$headers)){
$successMessage='<div class="alert alert-danger" role="alert"><p><strong>Your message was sent</strong></p>'. error . '</div>';
}
}
?>
このコードで何が間違っていますか?私はすでに構文とエラーとすべてをチェックしています。私は何が間違っているのか、なぜこれが起きているのか分かりません。 声明私のコードは最初のif文までうまくいきます。その後、私のコードが画面に表示されます。
可能な重複[PHPコードが実行され、代わりにコードがページに表示されていません]( https://stackoverflow.com/質問/ 5121495/php-code-is-being-being-with-pageの代わりにコード) – Qirel
私が見る問題のカップル: 'エラー'の代わりに 'エラー'を2回出力しています。また、$ headersを設定する場合は、ピリオドを使用して2つの値を連結する必要があります。その行は「From:」でなければなりません。 $ _POST( 'email'); – Dan