我的联系表格没有发送电子邮件

时间:2014-01-20 01:46:22

标签: php forms email contact

我一直在尝试设置联系表单,以便将信息发送到我的电子邮箱。我检查了代码,没有语法错误或任何东西,但我没有收到任何测试电子邮件。你能帮帮我吗?

这是HTML:

    <!--Start of Contact Form-->
    <div class="large-7 medium-10 small-12 medium-centered large-centered column">
        <div class="row">
            <form method="post" action="email2.php">

                    <input type="text" name="name" class="defaultText" title="your name">
                    <input type="text" name="email" class="defaultText" title="your email address">


                    <textarea name="comments1" class="defaultText" title="Tell us about your business"></textarea>
                    <textarea name="comments2" class="defaultText" title="How can we help?"></textarea>


               <div class="large-7 medium-10 small-12 medium-centered large-centered column">
                    <input type="submit" name="send message" value="Send Message">
                </div>
            </form>
        </div>
    </div>
    <!--End of Contact Form-->

这是脚本:

<?php

if (isset($_POST['email']))
//if "email" is filled out, send email
  {
  //send email
  $name = $_POST['name'] ;
  $email = $_POST['email'] ;
  $comments1 = $_POST['comments1'] ;
  $comments2 = $_POST['comments2'] ; 
  mail("info@muzedimage.com", $name, $email, $comments1, $comments2
 , "From:" . $email);
  echo "<script>window.location = 'http://www.muzedimage.com'</script>";
  }
else
//if "email" is not filled out,
  {
  echo "<script>window.location = 'http://www.muzedimage.com/contact'</script>";
  }
?>

我非常感谢帮助人员。

1 个答案:

答案 0 :(得分:0)

您的邮件功能传递了错误的参数。请阅读mail() documentation

格式正确

mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

在您的情况下,下面是正确的代码。

$to      = 'info@muzedimage.com';
$email   = $_POST['email'] ;
$subject = 'add some subject'; // no subject could lead to email being flagged as spam
$comments1 = $_POST['comments1'] ;
$comments2 = $_POST['comments2'] ; 
$message = $comments1 .  "\n\n" . $comments2;
$headers = "From: $email";

mail($to, $subject, $message, $headers);

您需要按照自己的意愿使用评论。在这种情况下,我假设它们都是主要信息。

希望有所帮助。并始终阅读文档!!