Apache2 html 站点不会从表单发送电子邮件,它会打开一个需要很长时间才能加载的空白页面

问题描述 投票:0回答:0

我有一个 html 网站,上面有一个联系我的表格。此表单的目的是向我发送一封包含表单内容的电子邮件。我已经安装了 postfix 并拥有 php7.4(这是 owncloud 使用的,其他项目但 php7.4 应该可以工作)。我有一个 .php 脚本,html 站点应该用来发送电子邮件。它不发送电子邮件,它加载了很长时间,然后最终在地址 example.com/contact-form-handler.php 上显示了一个空白页面,而不是发送电子邮件。它不显示 .php 文件的代码,它只是一个空白屏幕。我相关的 html snipit 和 .php 文件是

html文件

<div><b>Contact Me!</b></div>
<form method="post"action="contact-form-handler.php">
  <input class="formFormat" placeholder="Enter your Name" type="text" name="name">
  <input class="formFormat" placeholder="Enter your email" type="text" name="email">
  <textarea class="formFormat" placeholder="Enter your message" name="message"></textarea>
  <input class="sendButton" type="submit" value="Send">
</form> 

.php 文件

<?php 
$errors = '';
$myemail = '[email protected]';
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Contact form submission: $name";
    $email_body = "You have received a new message. ".
    " Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message"; 
    
    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email_address";
    
    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    // header('Location: index.html');
} 
?>
<!DOCTYPE HTML> 
<html>
<head>
    <title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>

我已经尝试查看为什么我的 php 无法正常工作,但我无处可去。有人有什么想法吗?

php html apache postfix-mta
© www.soinside.com 2019 - 2024. All rights reserved.