私の連絡フォームを有効にしようとしましたが、Gmailのフォルダにメールが届かない(スパムやゴミ箱を含む)ホスト)。PHPフォームに連絡する - メールを受信しない(GMAIL)
私はこのチュートリアルを追ってきた:http://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form
私はすべてを試みてきたようにいくつかの深刻な助けが必要!
<?php
$from = $_POST['email'];
$sendTo = '[email protected]';
$subject = 'New message from contact form';
$fields = array('name' => 'Name', 'surname' => 'Surname', 'email' => 'Email', 'phone' => 'Phone', 'message' => 'Message');
// array variable name => Text to appear in email
$okMessage = 'Contact form succesfully submitted. Thank you, I will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';
// let's do the sending
try
{
$emailText = "You have new message from contact form\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
mail($sendTo, $subject, $emailText, "From: " . $from);
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
HTMLのFORM
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="form-group">
<div class="row">
<div class="col-md-6 col-sm-12">
<label>First name*</label>
<input type="text" id="form-name" name="name" class="form- control" placeholder="Please enter your firstname *" required="required">
</div>
<div class="col-md-6 col-sm-12">
<label>Last name*</label>
<input type="text" name="surname" id="form-surname" class="form-control" placeholder="Please enter your firstname *" required="required">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6 col-sm-12">
<label>Email*</label>
<input type="email" name="email" id="form-email" class="form-control" placeholder="Please enter your firstname *" required="required">
</div>
<div class="col-md-6 col-sm-12">
<label>Phone</label>
<input type="tel" name="phone" id="form-phone" class="form- control" placeholder="Please enter your phone">
</div>
</div>
</div>
<div class="form-group">
<label for="comment">Message*</label>
<textarea class="form-control" rows="7" name="message" id="form-message" default="Type us a message" required="required"></textarea>
</div>
<div class="checkbox">
<label><input type="checkbox" value="">Join mailing list</label>
</div>
<input type="submit" class="btm btn-success btn-send" value="Send message">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</form>
エラーメッセージがありますか? –
あなたのホストはphp mail()をサポートしていますか? – AkshayP
提出時にわかるようなエラーメッセージはありません –