PHP代码不将表单发送到电子邮件

时间:2018-03-29 15:59:53

标签: php forms email

我正在尝试为联系表单设置表单到电子邮件的PHP代码,但我遇到了一些困难。我的脚本似乎运行,但它实际上并没有发送任何电子邮件。该文件保存在index.php下,并像我网站的所有其他文件一样放在我的public_html目录中。此外,我有一个电子邮件地址,使用我的网站托管我的域名。

这是我如何弹出代码,然后是有问题的代码。

<form method="post" action="index.php">



    <?php
// Check for submit
  // if(filter_has_var(INPUT_POST, 'submit')){
  if(isset($_POST['submit'])){
    // Get Form Data
    $name = htmlspecialchars($_POST['name']);
    $email = htmlspecialchars($_POST['email']);
    $phone = htmlspecialchars($_POST['phone']);
    $website = htmlspecialchars($_POST['website']);
    $message = htmlspecialchars($_POST['message']);

// Sending Email
    $toEmail = 'admin@thomascaissie.com';
    $subject = 'Contact Request From ' .$name;
    $body = '<h2>Contact Request</h2>
        <h4>Name</h4><p>'.$name.'</p>
        <h4>Email</h4><p>'.$email.'</p>
        <h4>Phone Number</h4><p>'.$phone.'</p>
        <h4>Website</h4><p>'.$website.'</p>
        <h4>Message</h4><p>'.$message.'</p>
        ';
  //Email Headers
    $headers = "MIME-Version: 1.0" ."\r\n";
    $headers .="Content-Type:text/html;charset=UTF-8" . "
          \r\n";

  //Additional Headers
    $headers .= "From: " .$name. "<".$email.">". "\r\n";
  }
?>

我犯了哪些错误?我的猜测是我甚至没有调用脚本来实际发送电子邮件。

0 个答案:

没有答案