我一直在努力使这个联系表单工作,但无法接收电子邮件。一切看起来都很好。我正在使用html模板并尝试使用我有限的编码知识进行自定义。任何帮助表示赞赏。
这是我的HTML代码:
<form class="form-horizontal" id="contactForm" action="contact.php" method="post">
<!-- Notifications -->
<p class="success cf text-center"><i class="fa fa-check"></i> <strong>Mesajınız Gönderilmiştir.</strong></p>
<p class="failed cf text-center"><i class="fa fa-exclamation-circle"></i><strong> Bir hata Oluştu! Lütfen Tekrar Deneyiniz.</strong></p>
<div class="form-group w-50">
<input type="text" class="form-control" id="cfName" placeholder="İsim" required="">
<input type="email" class="form-control" id="cfEmail" placeholder="E-Mail" required="">
</div>
<div class="form-group">
<input type="text" class="form-control" id="cfSubject" placeholder="Başlık" required="">
</div>
<div class="form-group">
<textarea id="cfMessage" rows="5" class="form-control" placeholder="Mesajınız..." required=""></textarea>
</div>
<div class="form-group m-b-0">
<button type="submit" class="btn btn-shadow btn-green" style="border-radius: 4px; font-size: 15px; box-shadow: rgb(72, 125, 101) 0px 0px 0px 0px; border: 3px solid rgb(219, 141, 23); background-color: rgb(219, 141, 23);">Gönder</button>
</div>
</form>
这是我的PHP代码:
<?php
// Variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
// Email address validation - works with php 5.2+
function is_email_valid($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
if( isset($name) && isset($email) && isset($message) && isset($subject) && is_email_valid($email) ) {
// Avoid Email Injection and Mail Form Script Hijacking
$pattern = "/(content-type|bcc:|cc:|to:)/i";
if( preg_match($pattern, $name) || preg_match($pattern, $email) || preg_match($pattern, $message) || preg_match($pattern, $subject) ) {
exit;
}
// Email will be send
$to = "arda@toptal.com"; // Change with your email address
// HTML Elements for Email Body
$body = <<<EOD
<strong>Name:</strong> $name <br>
<strong>Email:</strong> <a href="mailto:$email?subject=feedback" "email me">$email</a> <br> <br>
<strong>Message:</strong> $message <br>
EOD;
//Must end on first column
$headers = "From: $name <$email>\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// PHP email sender
mail($to, $subject, $body, $headers);
}
?>
&#13;
感谢。
答案 0 :(得分:0)
尝试这样的表单,将name属性设置为POST数组中预期的
<form class="form-horizontal" id="contactForm" action="contact.php" method="post">
<!-- Notifications -->
<p class="success cf text-center"><i class="fa fa-check"></i> <strong>Mesajınız Gönderilmiştir.</strong></p>
<p class="failed cf text-center"><i class="fa fa-exclamation-circle"></i><strong> Bir hata Oluştu! Lütfen Tekrar Deneyiniz.</strong></p>
<div class="form-group w-50">
<input name='name' type="text" class="form-control" id="cfName" placeholder="İsim" required="">
<input name='email' type="email" class="form-control" id="cfEmail" placeholder="E-Mail" required="">
</div>
<div class="form-group">
<input name='subject' type="text" class="form-control" id="cfSubject" placeholder="Başlık" required="">
</div>
<div class="form-group">
<textarea name='message' id="cfMessage" rows="5" class="form-control" placeholder="Mesajınız..." required=""></textarea>
</div>
<div class="form-group m-b-0">
<button type="submit" class="btn btn-shadow btn-green" style="border-radius: 4px; font-size: 15px; box-shadow: rgb(72, 125, 101) 0px 0px 0px 0px; border: 3px solid rgb(219, 141, 23); background-color: rgb(219, 141, 23);">Gönder</button>
</div>
</form>
答案 1 :(得分:0)
你错过了每个字段的名称
<form class="form-horizontal" id="contactForm" action="contact.php" method="post">
<!-- Notifications -->
<p class="success cf text-center"><i class="fa fa-check"></i> <strong>Mesajınız Gönderilmiştir.</strong></p>
<p class="failed cf text-center"><i class="fa fa-exclamation-circle"></i><strong> Bir hata Oluştu! Lütfen Tekrar Deneyiniz.</strong></p>
<div class="form-group w-50">
<input type="text" class="form-control" name="name" id="cfName" placeholder="İsim" required="">
<input type="email" class="form-control" name="email" id="cfEmail" placeholder="E-Mail" required="">
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="cfSubject" placeholder="Başlık" required="">
</div>
<div class="form-group">
<textarea id="cfMessage" name="message" rows="5" class="form-control" placeholder="Mesajınız..." required=""></textarea>
</div>
<div class="form-group m-b-0">
<button type="submit" class="btn btn-shadow btn-green" style="border-radius: 4px; font-size: 15px; box-shadow: rgb(72, 125, 101) 0px 0px 0px 0px; border: 3px solid rgb(219, 141, 23); background-color: rgb(219, 141, 23);">Gönder</button>
答案 2 :(得分:0)
您缺少输入类型字段名称,说明无法将数据传递到下一页的原因&#34; contact.php&#34;
<form class="form-horizontal" id="contactForm" action="contact.php" method="post">
<!-- Notifications -->
<p class="success cf text-center"><i class="fa fa-check"></i> <strong>Mesajınız Gönderilmiştir.</strong></p>
<p class="failed cf text-center"><i class="fa fa-exclamation-circle"></i><strong> Bir hata Oluştu! Lütfen Tekrar Deneyiniz.</strong></p>
<div class="form-group w-50">
<label>Username*</label>
<input type="text" name="name" class="form-control" id="cfName" placeholder="Username" required="">
</div>
<div class="form-group w-50">
<label>Email*</label>
<input type="email" name="email" class="form-control" id="cfEmail" placeholder="E-Mail" required="">
</div>
<div class="form-group">
<label>Subject*</label>
<input type="text" name="subject" class="form-control" id="cfSubject" placeholder="Subject" required="">
</div>
<div class="form-group">
<label>Message*</label>
<textarea id="cfMessage" name="message" rows="5" class="form-control" placeholder="Message..." required=""></textarea>
</div>
<div class="form-group m-b-0">
<button type="submit" class="btn btn-shadow btn-green" style="border-radius: 4px; font-size: 15px; box-shadow: rgb(72, 125, 101) 0px 0px 0px 0px; border: 3px solid rgb(219, 141, 23); background-color: rgb(219, 141, 23);">Gönder</button>
</div>
</form>