【问题标题】:My contact form is not sending email我的联系表格没有发送电子邮件
【发布时间】:2014-01-20 01:46:21
【问题描述】:

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

这是 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>";
  }
?>

非常感谢各位的帮助。

【问题讨论】:

  • 问题在于如何将这些变量分配给它们的特定参数。您提供的标题不正确,因此邮件被拒绝。请read more about mail().
  • 人们只是猜测函数接受的参数吗?

标签: php forms email contact


【解决方案1】:

您向邮件函数传递了错误的参数。请阅读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);

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

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

【讨论】:

  • @user3213485 似乎您已经想通了。祝你好运,编码愉快。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-16
  • 2011-08-12
  • 2018-05-09
  • 1970-01-01
  • 2015-09-22
  • 2012-04-30
  • 2013-12-29
相关资源
最近更新 更多