php - 使用php发送邮件报错

标签 php html email

<分区>

所以有一个单一的表格,它只获取该人的电子邮件并将其发送到我指定的电子邮件地址。但我想我以错误的方式编写了代码,因为我遇到了错误。我已经看到其他 stackoverflow 问题,但我不确定为什么这不起作用。 这是 html 中的表单。

<form style="margin-bottom:50px;" name="contactform" action="contact-form-handler.php" class="news-letter "method="post">
  <div class="subscribe-hide">
    <input type="text" name="email" class="form-control"  placeholder="Email Address"  >
    <button  type="submit"  class="btn"><i class="fa fa-envelope"></i></button>
  </div><!-- /.subscribe-hide -->
</form><!-- /.news-letter -->

这是另一个文件中的 PHP 代码。

    <?php
$errors = '';
$myemail = 'masnadhossain@live.com';
   empty($_POST['email']))
{
    $errors .= "\n Error: all fields are required";
}

$email_address = $_POST['email'];

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";
$email_body = "You have received a new message. ".
" Here are the details:".
"Email: $email_address\n ";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}

?>

我得到的错误是服务器错误 500

最佳答案

您的代码有语法错误,请检查。

第 3 行应该是:

if (empty($_POST['email']))
{
    $errors .= "\n Error: all fields are required";
}

关于php - 使用php发送邮件报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34489562/

相关文章:

javascript - HTML 页面上的 iframe

java : Send Email from Server which is connected in LAN but Not in Internet

php - 在php中从outlook csv导入联系人

php - 将数据库中的数据显示到html表中

javascript - 如何在 HTML + Javascript/JQuery 中启用/禁用下拉列表框?

java - jsf 正则表达式验证期间允许使用 ascii 字符

linux - 如何在 Linux 终端中创建电子邮件帐户/地址?

php - 在 Yii2 搜索中比较匹配的数组索引值

php - mySQL/PHP 查询不受日期限制

php - PHP 自动分配数组功能的 javascript 等价物是什么?