提问人:James941 提问时间:10/15/2023 最后编辑:BarmarJames941 更新时间:10/15/2023 访问量:39
从 IONIS 迁移到 Hostinger 后,我网站上的 PHP 联系表不再按预期工作
PHP contact form on my website no longer working as intended after migrating from IONIS to Hostinger
问:
我有一份我多年前写的联系表格,多年来一直完美无缺。2 天前,我将我的域名迁移到了 Hostinger。从那时起,它就没有按预期工作。用户会收到确认电子邮件,但无论我输入什么电子邮件地址,我都不会收到联系表单回复。任何指导将不胜感激!
我认为这更有可能是 Hostinger 方面/域设置的问题,而不是以前工作的代码,但如果有兴趣,请参阅下面的代码。
<?php
// BEGIN CONFIGURATION ////////////////////////////////////////////////
define('EMAIL_TO', 'insert email here');
define('CC_TO', 'insert email here');
define('BCC_TO', 'insert email here');
define('EMAIL_SUBJECT', 'WEB Contact Form');
define('COPY_SUBJECT', 'Copy of WEB Contact Form');
define('CAPTCHA_ENABLED', '0'); // 0 - Disabled, 1 - Enabled
// END CONFIGURATION ////////////////////////////////////////////////
define('CAPTCHA1', rand(1,19));
define('CAPTCHA2', rand(1,19));
if ($_GET) {
$name = $_GET['name']; //$name = filter_input(INPUT_POST, "name");
$email = $_GET['email']; //$email = filter_input(INPUT_POST, "email");
$message = $_GET['message']; //$message = filter_input(INPUT_POST, "message");
$when = "Message sent: " . date("Y-m-d @ h:ia");
// $captcha = $_POST['captcha'];
// $captcha1 = $_POST['captcha1'];
// $captcha2 = $_POST['captcha2'];
// If captcha disabled, set variable values to avoid error
if (CAPTCHA_ENABLED == '0') { $captcha1 = '1'; $captcha2 = '1'; $captcha = '2'; }
// Error handling
if (empty($name) || empty($email) || empty($message)) { print "<p>Testing Mode - Success - Please fill all fields</p> "; }
else if (!$email == '' && (!strstr($email,'@') || !strstr($email,'.'))) { print "<p>Testing Mode - Success - Please check your email address</p> "; }
else if (($captcha1 + $captcha2) != $captcha) { print "<p>Testing Mode - Success - Anti-spam entry is incorrect. Please try again.</p> "; }
// Build email headers
else {
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "From: ".$name." <".$email.">\r\n";
$headers .= "Reply-To: ".$name." <".$email.">\r\n";
// $headers .= "Cc: ".CC_TO. "\r\n";
// $headers .= "Bcc: ".BCC_TO. "\r\n";
// Build message email body
$body = '
<html><body>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td style="font-size:18px; font-weight:bold; padding:10px;" colspan="2">Website Contact Form Message</td></tr>
<tr><td style="border-bottom: solid 2px #CCC; font-size:18px; padding:10px;" colspan="2">'.$when.'</td></tr>
<tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>Name:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">'.$name.'</td></tr>
<tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>Email:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">'.$email.'</td></tr>
<tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>Message:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">'.$message.'</td></tr>
</table>
</body></html>
';
// Send the message email
mail(EMAIL_TO, EMAIL_SUBJECT, $body, $headers);
// Build confirmation email headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "From: Name
<[email protected]>\r\n";
$headers .= "Reply-To: Mitch Peacock <[email protected]>\r\n";
// Build confirmation email body
$body = '
<html><body>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td style="border-bottom: solid 2px #CCC; font-size:18px; font-weight:bold; padding:10px;" colspan="2">Message Confirmation</td></tr>
<tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>From:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">Website of Mitch Peacock</td></tr>
<tr><td valign="top" style="padding:10px; border-bottom: solid 1px #CCC;" valign="top"><b>Your Email:</b></td><td style="padding:10px; border-bottom: solid 1px #CCC;">'.$email.'</td></tr>
<tr><td valign="top" style="padding:10px; border-bottom: solid 2px #CCC;" valign="top"><b>Your message:</b></td><td style="padding:10px; border-bottom: solid 2px #CCC;">'.$message.'</td></tr>
<tr><td style="border-bottom: solid 1px #CCC; font-size:18px; font-weight:bold; padding:10px;" colspan="2">Thanks for your message, I shall respond as soon as possible</td></tr>
<tr><td style="color:red; padding:10px;" colspan="2">Replies direct to this email address ([email protected]) are not monitored</td></tr>
</table>
</body></html>
';
// Send the email, reset text boxes on form, and show success message
mail($email, 'Confirmation', $body, $headers);
print "<p>Thanks for your message</p> ";
$name = '';
$email = '';
$message = '';
}
}
else {print "<p>Error, No data recived! Please try again</p> ";}
?>
答: 暂无答案
评论