繁体   English   中英

PHP mail()未发送电子邮件

[英]PHP mail() is not sending email

我将以下代码用于HTML中的联系表单:

  <form method="post" name="contact_form"
action="contact-form-handler.php" data-add-back-btn="false" data-ajax="false">
    Your Name:
      <span id="sprytextfield1">
      <input type="text" name="name">
      <span class="textfieldRequiredMsg">A value is required.</span></span> 
      Code:
      <span id="sprytextfield1">
      <input type="text" name="code">
      <span class="textfieldRequiredMsg">A value is required.</span></span> 
      Email Address:
      <span id="sprytextfield2">
      <input type="text" name="email">
      <span class="textfieldRequiredMsg">A value is required.</span></span> Message:
<textarea name="message"></textarea>
    <input type="submit" value="Submit">
</form>

那是处理邮件功能的PHP文件:

<?php
$errors = '';
$myemail = 'email';//<-----Real email address here.
if(empty($_POST['name'])  ||  empty($_POST['code'])  ||
   empty($_POST['email']) ||
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$code = $_POST['code'];
$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".
"Codigo: $code\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');
}
?>

用户填写表单并单击“提交”按钮后,将打开“谢谢”页面,但不会通过电子邮件发送表单。

欢迎任何帮助。

如果mail()返回true ,则联系托管人的客户服务

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM