私は現地でメールを送信するためにPHPフォームをテストしています。PHP送信フォームが正しく動作しない
私はすべての入力を入れますが、送信ボタンを押すと常に「false」とエラーメッセージが返されます。それは私がローカルで働いていて、メールサーバーを持っていないか、コードに何か間違っているからですか?ここ
コード:
<?php
if(isset($_POST['submit']))
{
if(empty($_POST['nome']) ||
empty($_POST['email']) ||
empty($_POST['motivo']) ||
empty($_POST['messaggio']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
// return false;
}
else
{
$nome = strip_tags(htmlspecialchars($_POST['nome']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$motivo = strip_tags(htmlspecialchars($_POST['motivo']));
$messaggio = strip_tags(htmlspecialchars($_POST['messaggio']));
// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "Website Contact Form: $nome";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $nome\n\nEmail: $email_address\n\nOggetto: $motivo\n\nMessaggio:\n$messaggio";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected]
$headers .= "Reply-To: $email_address";
if ([email protected]($to,$email_subject,$email_body,$headers))
{
// return true;
echo "<p>Email error</p>";
}
else
{
echo "<p>Email sent successfully!</p>";
}
}
}
?>
<form class="form-horizontal col-sm-6 col-sm-offset-3" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST">
<div class="form-group">
<div class="row">
<label for="email" class="col-sm-12">Email</label>
</div>
<div class="row">
<div class="col-sm-12">
<input type="email" name="email" class="form-control" id="email" placeholder="Email">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label for="nome" class="col-sm-12">Nome</label>
</div>
<div class="row">
<div class="col-sm-12">
<input type="text" name="nome" class="form-control" id="nome" placeholder="Nome">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label for="motivo" class="col-sm-12">Motivo</label>
</div>
<div class="row">
<div class="col-sm-12">
<input type="text" name="motivo" class="form-control" id="motivo" placeholder="Motivo">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<label for="messaggio" class="col-sm-12">Messaggio</label>
</div>
<div class="row">
<div class="col-sm-12">
<textarea class="form-control" name="messaggio" rows="5" id="messaggio" placeholder="Motivo">Inserisci il tuo messaggio...</textarea>
</div>
</div>
</div>
<div class="form-group">
<div class="">
<button type="submit" name="submit" class="btn btn-default">Invia</button>
</div>
</div>
</form>
任意のヘルプ?
「エラー」とは何ですか? – Jagrati
はあなたの 'error'メッセージに完全に依存します。投稿する! – Pragun
デバッグヘルプ(「なぜこのコードは動作しませんか?」)には、目的の動作、特定の問題またはエラー、および質問自体に再現するのに必要な最短コードが含まれている必要があります。明確な問題文がない質問は、他の読者にとって有用ではありません。参照:[mcve]を作成する方法。 – xenteros