0

我对 PHP 很陌生,我需要一个联系表,所以我从互联网上取下了一个并编辑了我需要/想要的所有内容。邮件不会发送,所以如果有人能帮我解决这个问题,我会很高兴!

HTML:

        <form name="contactform" method="post"action="send_form_email.php">
        <p class="name">
        <input type="text" name="first_name" id="name" placeholder="Fullständigt namn" />
        </p>

        <p class="foretag">
        <input type="text" name="foretag" id="foretag" placeholder="Företag" />
        </p>

        <p class="email">
        <input type="text" name="email" id="email" placeholder="Email" />
        </p>

        <p class="telefon">
        <input type="text" name="telephone" id="telephone" placeholder="Telefonnummer" />
        </p>        

        <p class="text">
        <textarea name="text" id="text" placeholder="Meddelande" /></textarea>
        </p>

        <p class="robotic" id="pot">
        <label>Om du är människa, fyll inte i denna ruta:</label>
        <input name="robotest" type="text" id="robotest" class="robotest" />
        </p>

        <p class="submit">
        <input type="submit" value="Skicka" />
        </p>
        </form>
</div>

PHP:

    <?php
    if(isset($_POST['email'])) {


        $email_to = "EMAIL HERE";
        $email_subject ="subject";


        function died($error) {
            // your error code can go here
            echo "Fel uppstog";
            echo "Error kod:.<br /><br />";
                 echo $error."<br /><br />";
            echo "Gå tillbaka och rätta till problemen innan du försöker igen.<br /><br />";
            die();
        }

        // validation expected data exists
        if(!isset($_POST['first_name']) ||
            !isset($_POST['foretag']) ||
            !isset($_POST['email']) ||
            !isset($_POST['telephone']) ||
            !isset($_POST['text'])) {
            died('Det verkar vara ett problem med formuläret du angav');       
        }

        $first_name = $_POST['first_name'];
        $foretag = $_POST['foretag'];
        $email = $_POST['email'];
        $telephone = $_POST['telephone'];
        $text = $_POST['text'];

        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email)) {
        $error_message .= 'Emailadressen du angav verkar inte vara giltig.<br />';
      }
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$first_name)) {
        $error_message .= 'Namnet du angav verkar inte vara giltig.<br />';
      }
      if(!preg_match($string_exp,$foretag)) {
        $error_message .= 'Företaget du angav är inte giltig..<br />';
      }
      if(strlen($text) < 2) {
        $error_message .= 'Meddelandet du angav är inte giltig..<br />';
      }
      if(strlen($error_message) > 0) {
        died($error_message);
      }
        $email_message = "Form details below.\n\n";

        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }

        $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Last Name: ".clean_string($last_name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Telephone: ".clean_string($telephone)."\n";
        $email_message .= "Comments: ".clean_string($comments)."\n";

if (preg_match("/http/i", "$first_name")) {echo "$spamErrorMessage"; exit();}
        if (preg_match("/http/i", "$email")) {echo "$spamErrorMessage"; exit();}
        if (preg_match("/http/i", "$telephone")) {echo "$spamErrorMessage";exit();}
        if (preg_match("/http/i", "$text")) {echo "$spamErrorMessage"; exit();}

         $SpamErrorMessage = "Ingen URL tillåten";

         $headers = 'From: '.$email_from."\r\n";
         'Reply-To: '.$email_from."\r\n" .
        'X-Mailer: PHP/' . phpversion();


        if($robotest)
            $error = "You are a gutless robot.";
        else {
    @mail($email_to, $email_subject, $email_message, $headers); 
    }
         }
    ?>
4

2 回答 2

0
<input type="text" name="name" id="name" placeholder="Fullständigt namn" />

应该

<input type="text" name="first_name" id="name" placeholder="Fullständigt namn" />
于 2013-08-25T13:31:22.907 回答
-2

我不得不修改您的表单和 PHP 处理程序中的一些内容,以使所有字段都匹配和工作。

注意:您需要用您自己的语言修改一些内容,但除此之外,这对我有用,并且电子邮件实际上已发送和接收。

HTML 表单

<form name="contactform" method="post" action="send_form_email.php">
    <p class="name">
    <input type="text" name="first_name" id="first_name" placeholder="Fullständigt namn" />
    </p>

    <p class="last_name">
    <input type="text" name="last_name" id="last_name" placeholder="Last name" />
    </p>

    <p class="foretag">
    <input type="text" name="foretag" id="foretag" placeholder="Företag" />
    </p>

    <p class="email">
    <input type="text" name="email_from" id="email" placeholder="Email" />
    </p>

    <p class="telefon">
    <input type="text" name="telephone" id="telephone" placeholder="Telefonnummer" />
    </p>        

    <p class="text">
    <textarea name="text" id="text" placeholder="Meddelande" /></textarea>
    </p>

    <p class="robotic" id="pot">
    <label>Om du är människa, full inte i denna ruta:</label>
    <input name="robotest" type="text" id="robotest" class="robotest" />
    </p>

    <p class="submit">
    <input type="submit" value="Skicka" />
    </p>
    </form>
</div>

PHP 处理程序 (send_form_email.php)

<?php
    if(isset($_POST['email_from'])) {


        $email_to = "email@example.com";
        $email_subject = "bezod-design kontakta";

         // } this could be used, didn't make much of a difference.
         // closing brace for this is commented at the end of this code
         // but you will need to delete the closing brace at the end if using the closing brace here
        function died($error) {
            // your error code can go here
            echo "Erros uppstog";
            echo "Dem/det är listade nedan.<br /><br />";
                 echo $error."<br /><br />";
            echo "Gå tillbaks och fix dem innan du skickar.<br /><br />";
            die();
        }

        // validation expected data exists
        if(!isset($_POST['first_name']) ||
            !isset($_POST['last_name']) ||
            !isset($_POST['foretag']) ||
            !isset($_POST['email_from']) ||
            !isset($_POST['telephone']) ||
            !isset($_POST['text'])) {
            died('Det värkar vara ett problem med formuläret du skrev');       
        }

        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $foretag = $_POST['foretag'];
        $email_from = $_POST['email_from'];
        $telephone = $_POST['telephone'];
        $text = $_POST['text'];

        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'Email adressen du skrev värkar inte vara giltig.<br />';
      }
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$first_name)) {
        $error_message .= 'Namnet adressen du skrev värkar inte vara giltig.<br />';
      }
      if(!preg_match($string_exp,$foretag)) {
        $error_message .= 'Företaget du skrev värkar inte vara giltig..<br />';
      }
      if(strlen($text) < 2) {
        $error_message .= 'Meddelandet du skrev värkar inte vara giltig..<br />';
      }
      if(strlen($error_message) > 0) {
        died($error_message);
      }
        $email_message = "Form details below.\n\n";

        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }

        $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Last Name: ".clean_string($last_name)."\n";
        $email_message .= "Foretag: ".clean_string($foretag)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Telephone: ".clean_string($telephone)."\n";
        $email_message .= "Comments: ".clean_string($text)."\n";

if (preg_match("/http/i", "$first_name")) {echo "$spamErrorMessage"; exit();}
        if (preg_match("/http/i", "$email_from")) {echo "$spamErrorMessage"; exit();}
        if (preg_match("/http/i", "$telephone")) {echo "$spamErrorMessage";exit();}
        if (preg_match("/http/i", "$text")) {echo "$spamErrorMessage"; exit();}

         $SpamErrorMessage = "Ingen URL tillåten";

         $headers = 'From: '.$email_from."\r\n";
         'Reply-To: '.$email_from."\r\n" .
        'X-Mailer: PHP/' . phpversion();


        if($robotest)
            $error = "You are a gutless robot.";
        else {
    mail($email_to, $email_subject, $email_message, $headers); 
    echo "Message sent.";
        }
    } // closing brace for if(isset at beginning of handler
     // delete this brace if you are to use the closing one at the beginning
?>
于 2013-08-25T13:54:55.900 回答