PHP mail()不发送电子邮件

时间:2014-08-20 15:14:45

标签: php email

这是我的第一篇文章,希望有一个简单的答案:

因此,根据主题标题,我无法通过表格发送电子邮件。

这是HTML代码:

                <form method="post" action="email.php">
                <div class="row half">
                    <div class="6u"><input type="text" class="text" name="name" placeholder="Name" /></div>
                    <div class="6u"><input type="text" class="text" name="email" placeholder="Email" /></div>
                </div>
                <div class="row">
                    <div class="12u"><input type="text" class="text" name="subject" placeholder="Subject" /></div>
                </div>
                <div class="row half">
                    <div class="12u">
                        <textarea name="message" placeholder="Message"></textarea>
                    </div>
                </div>
                <div class="row">
                    <div class="12u">
                        <ul class="actions">
                            <li><input type="submit" value="Send Message" /></li>
                            <li><input type="reset" value="Reset" name="reset"/></li>
                        </ul>
                    </div>
                </div>
            </form>

这是PHP代码:

<?php
  //Required Input Fields

    $name = check_input($_POST['name'], "<p>Please Enter Your Name!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
    $email = check_input($_POST['email'], "<p>Please Enter Your Email Address!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
    $subject = check_input($_POST['subject'], "<p>Please Enter a Subject!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");
    $message = check_input($_POST['message'], "<p>Please Enter Your Message!</p><p><a href='#' onclick='history.go(-1)' class='button style2 scrolly scrolly-centered'>Go Back</a></p>");

  //Html Error

    $SpamErrorMessage = "<p>No Website URLs Permitted!</p><br  /><p><a href='#' onclick='history.go(-1)'>Go Back</a></p>";
    if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}
    if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
    if (preg_match("/http/i", "$subject")) {echo "$SpamErrorMessage"; exit();}
    if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();}

  //Email Validation

    $email = htmlspecialchars($_POST['email']);
    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
    {
      die("<p>We're Sorry, Your Email Address Does Not Appear to Be Valid.</p><p><a href='#' onclick='history.go(-1)'>Go Back</a></p>");
    }

  //Function Check to Eliminate Unwanted Characters, Strips Quotes, and Adds HTMLSpecialCharacters

    function check_input($data, $problem='')
    {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      if ($problem && strlen($data) == 0)
      {
         die($problem);
      }
      return $data;
    }

  //Sends Email and Forwards to Thank You Page

    mail('*****@gmail.com', $subject, $message, '-f$email');
        echo "<h2><p>Thank you for your message. <br  /> We will reply back to you shortly.</h2><p><a href='http://www.*****.co.uk' class='button style2 scrolly scrolly-centered'>Click here to return</a></p>";
?>

任何人都可以解决可能出错的问题吗? 运行代码的服务器没有SMTP服务器。 这可能导致代码失败吗?

谢谢

0 个答案:

没有答案