【发布时间】:2020-11-04 21:07:04
【问题描述】:
我创建了一个简单的联系表单,应该通过 php 向我发送电子邮件但是,当我尝试发送/提交表单时,我继续收到“消息失败”输出并确认我的 gmail 没有任何内容收件箱。
我已进入我的主机服务器(中心地带)并尝试将 Php.ini 端口更新为(25 和 2525)并将我的 SMTP 更改为主机邮件服务器。我检查了我的错误日志并解决了报告的所有错误。我不确定问题出在我的主机服务器还是我的实际 php/form 代码中。
表单代码
<h2>Contact Form</h2>
<form id="contactForm" method="POST" action="formHandler.php">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required data-error="Please enter your name">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="text" placeholder="Email" id="email" class="form-control" name="email" required data-error="Please enter your email">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input type="text" placeholder="Subject" id="msg_subject" class="form-control" required data-error="Please enter your subject">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<textarea class="form-control" id="message" name="message" placeholder="Your Message" rows="5" data-error="Write your message" required></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="submit-button">
<button class="btn btn-common" id="submit" type="submit" value="submit" target="_blank">Send Message</button>
<div id="msgSubmit" class="h3 text-center hidden"></div>
<div class="clearfix"></div>
</div>
</div>
</div>
</form>
PHP 代码
<?php
if(isset($_POST['submit'])){
$to = "myemail@gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email: $email \n Message: $message";
$subject = "Contact Form";
$mailheader = "From: $email \r \n";
mail($to, $mailheader, $subject, $formcontent);
echo "<p>Thank you for contacting me!</p>";
echo "<p>I will reply to your inquiry in 24-48 business hours.</p>";
echo "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
else{
echo "<p> Message Failed to Send.</p>";
echo "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
【问题讨论】:
标签: php html forms email server