php - 我正在尝试使用 HTML 和 PHP 与我联系,但在发送消息时出现错误
问题描述
我正在尝试使用 HTML 和 PHP 创建一个与我联系的表单,但是每当有人尝试向我发送消息时,它都会出错。
这是我的 HTML 代码:
<div class="col-lg-9">
<form class="row contact_form" action="contact_process.php" method="post" id="contactForm" novalidate="novalidate">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Enter your name">
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email address">
</div>
<div class="form-group">
<input type="text" class="form-control" id="subject" name="subject" placeholder="Enter Subject">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" name="message" id="message" rows="1" placeholder="Enter Message"></textarea>
</div>
</div>
<div class="col-md-12 text-right">
<button type="submit" value="submit" class="primary_btn">
<span>Send Message</span>
</button>
</div>
</form>
</div>
它与一个 PHP 文件 contact_process.php 相关联,它是:
<?php
$to = "mygmail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$subject = $_REQUEST['subject'];
$number = $_REQUEST['number'];
$cmessage = $_REQUEST['message'];
$headers = "From: $from";
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "You have a message from your Bitmap Photography.";
$logo = 'img/logo.png';
$link = '#';
$body = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>Express Mail</title></head><body>";
$body .= "<table style='width: 100%;'>";
$body .= "<thead style='text-align: center;'><tr><td style='border:none;' colspan='2'>";
$body .= "<a href='{$link}'><img src='{$logo}' alt=''></a><br><br>";
$body .= "</td></tr></thead><tbody><tr>";
$body .= "<td style='border:none;'><strong>Name:</strong> {$name}</td>";
$body .= "<td style='border:none;'><strong>Email:</strong> {$from}</td>";
$body .= "</tr>";
$body .= "<tr><td style='border:none;'><strong>Subject:</strong> {$csubject}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td colspan='2' style='border:none;'>{$cmessage}</td></tr>";
$body .= "</tbody></table>";
$body .= "</body></html>";
$send = mail($to, $subject, $body, $headers);
?>
所以你能告诉我我在哪里做错了吗
解决方案
更改代码(所有变量):
$number = $_REQUEST['number'];
至
$number = $_POST['number'];
对于检查邮件发送的更改:
$send = mail($to, $subject, $body, $headers);
至
if(mail($to, $subject, $body, $headers)){
echo 'done';
}else{
echo 'mail not sent';
}
推荐阅读
- sql - Group BY 语句错误以获取唯一记录
- docker - 运行 DockerFile 时找不到文件异常
- c# - C#如何用另一个点击事件终止一个点击事件处理程序
- android - 传入的语音未在 Android 中录制
- javascript - 分页没有在页面刷新时初始化,整个页面光滑库中的多个滑块
- sql - Select data where condition matches and if none, then select all?
- windows - 如何使python命令行参数在新行中继续
- c# - 如何从.net核心中的json文件中读取复杂对象
- vba - ADO 错误 没有足够的内存资源来完成此操作
- android - Volley 解析 Json 对象,文件发送字符串到服务器