php - PHP表单未向指定地址发送电子邮件
问题描述
我的网站上有一个联系表格,突然间,电子邮件停止发送。我检查了主机和网络邮件,一切正常(我什至发布到不同的电子邮件地址)。因此,我假设联系表格以某种方式损坏,因为当我发送消息时,我们什么也没有收到。我对 PHP 有点生疏。如果有人知道编写我们目前拥有的代码的更好方法,将不胜感激。
<?php
include ('includes/config.php');
$error = array();
$name = '';
$email = '';
$telephone = '';
$message = '';
if (isset($_POST['Send']))
{
// Assign form data
$name = $_POST['Name'];
$email = $_POST['Email'];
$telephone = $_POST['Telephone'];
$message = $_POST['Message'];
// Check for errors
if (empty($name)) { $error[] = 'Name'; }
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) { $error[] = 'Email'; }
if (empty($telephone)) { $error[] = 'Telephone'; }
if (empty($message)) { $error[] = 'Message'; }
// If no errors
if (sizeof($error) < 1) {
// Build message
$message = "Name: $name \n Email: $email \n Telephone: $telephone \n" . $message;
// Send email
mail('info@EXAMPLE.co.uk', "Example Message From $name", $message);
// Reset form
$name = '';
$email = '';
$telephone = '';
$message = '';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Us | <?=SITE_NAME?></title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include ('includes/header.php'); ?>
<div id="wrapper">
<div id="main">
<h1>Contact Us</h1>
<?php
if (sizeof($error) > 0)
{
echo '<p>There were errors for the following fields:</p><ul>';
foreach ($error as $val) {
echo "<li>$val</li>";
}
echo '</ul>';
}
else
{
echo '<p>Thank you for contacting us, we will get back to you shortly.</p>';
}
?>
<table cellpadding="5" cellspacing="0">
<form method="post" action="">
<tr>
<td width="150"><label for="Name">Name: </label></td>
<td><input type="text" name="Name" value="<?=$name?>" /></td>
</tr>
<tr>
<td><label for="Email">Email: </label></td>
<td><input type="text" name="Email" value="<?=$email?>" /></td>
</tr>
<tr>
<td><label for="Telephone">Telephone: </label></td>
<td><input type="text" name="Telephone" value="<?=$telephone?>" /></td>
</tr>
<tr>
<td valign="top"><label for="Message">Message: </label></td>
<td><textarea name="Message" rows="10" cols="55"><?=$message?></textarea></td>
</tr>
<tr>
<td></td>
<td><button type="submit" name="Send">Send Message</button></td>
</tr>
</form>
</table>
</div>
<?php include ('includes/footer.php'); ?>
</div>
</body>
</html>
解决方案
推荐阅读
- python - 在指定位置创建均值 = 1 的高斯二维数组
- azure-devops - Azure DevOps AAD 选项卡将不存在的用户显示为已断开连接
- node.js - Postgres NodeJS 批量更新插入超时
- javascript - 用数据 ASP.NET CORE MVC Jquery 填充弹出模式
- php - Windows Server (IIS) + PHP7.4 - curl 的问题
- python - 无法将 chromedriver page_source 写入文件
- javascript - Discord.js Bot 在启动时抛出错误。我该如何解决?
- sql - 上一个值的 SQL 帮助
- angular - 单元测试 Angular:当多次使用 control.setValue(...) 时,valueChanges 仅在测试结束时触发
- visual-studio - 找不到 dll 视觉工作室