PHP联系表单电子邮件错误

时间:2017-03-27 19:58:38

标签: php email contact-form

我在我的网站上有这个我想要的电子邮件表单,我之前尝试过它并且工作得很好,但是现在它突然停止工作并且由于某种原因不会发送邮件...我没有改变任何东西代码,不知道如何解决它......

以下是使用的代码:

<?php
if(!isset($_POST['submit']))
{
 //This page should not be accessed directly. Need to submit the form.
 echo "fel; du måste ha skickat!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

//Validate first
if(empty($name)||empty($visitor_email)) 
{
    echo "Namn och mailaddress är obligatoriskt!";
    exit;
}

if(IsInjected($visitor_email))
{
    echo "Fel mailaddress!";
    exit;
}

$email_from = 'info@beni.se';//<== update the email address
$email_subject = "Nytt meddelande";
$email_body = "Nytt meddelande från $name.\n \n".
    "Han/hon skrev:\n \n $message\n \n $visitor_email \n \n \n".
    
$to = "info@beni.se";//<== update the email address
$headers = "From: $visitor_email \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');

?> 
<!-- =====================START contact form===================== -->
 <div class="row scroll wow animated flash" id="contact-form" style="height: 100%; animation-delay: 0.5s;">
  <div class="col-md-4 col-sm-12 panel panel-default features email-block" style="padding-left: 0; padding-right: 0; border-radius: 15px; margin: 0;">
   <div class="panel-heading" style="border-top-left-radius: 15px; border-top-right-radius: 15px;">
    <h1 style="margin-top: 10px;">Anlita oss nu!</h1>
   </div><!-- //.panel-heading -->
   <div class="panel-body" style="padding-right: 0; padding-bottom: 0; padding-left: 0;">
    <form method="post" name="myemailform" action="form-to-email.php">
     <p>
      <label for='name'>Fullständiga namn: </label><br>
      <input type="text" placeholder="John Svensson" style="width: 300px; border-radius: 5px;" name="name">
     </p>
     <p>
      <label for='email'>Mailaddress:</label><br>
      <input type="text" placeholder="exempel@domän.se" style="width: 300px; border-radius: 5px;" name="email">
     </p>
     <p>
      <label for='message'>Meddelande:</label> <br>
      <textarea name="message" placeholder="Skriv ett meddelande..." style="width: 300px; height: 125px; border-radius: 5px; resize: none;"></textarea>
     </p>
     <input class="btn btn-warning btn-block" style="border-radius: 0px; border-bottom-right-radius: 15px; border-bottom-left-radius: 15px;" type="submit" name='submit' value="Skicka">
    </form>
    <script language="JavaScript">
    // Code for validating the form
    // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
    // for details
    var frmvalidator  = new Validator("myemailform");
    frmvalidator.addValidation("name","req","Var god och skriv in ditt namn.");
    frmvalidator.addValidation("email","req","Var god och skriv in din mailaddress.");
    frmvalidator.addValidation("email","email","Var god och skriv in en giltig mailaddress.");
    </script>
   </div><!-- //.col-md-4 panel-body -->
  </div><!-- //.panel -->
 </div><!-- //.row -->
<!-- =====================END contact form===================== -->

我尝试在mail($to,$email_subject,$email_body,$headers);

之前使用此功能
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");

当我使用它时,我得到:

    int(2)
string(164) "mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()"
string(59) "D:\HostingSpaces\rtruintm\beni.se\wwwroot\form-to-email.php"
int(36)
array(12) {
  ["_GET"]=>
  array(0) {
  }
  ["_POST"]=>
  array(4) {
    ["name"]=>
    string(10) "Bence Papp"
    ["email"]=>
    string(16) "test@hotmail.com"
    ["message"]=>
    string(6) "meh :c"
    ["submit"]=>
    string(6) "Skicka"
  }
  ["_COOKIE"]=>
  array(0) {
  }
  ["_FILES"]=>
  array(0) {
  }
  ["name"]=>
  string(10) "Bence Papp"
  ["visitor_email"]=>
  string(16) "test@hotmail.com"
  ["message"]=>
  string(6) "meh :c"
  ["email_from"]=>
  string(12) "info@beni.se"
  ["email_subject"]=>
  string(15) "Nytt meddelande"
  ["email_body"]=>
  string(98) "Nytt meddelande från Bence Papp.

Han/hon skrev:

 meh :c

 test@hotmail.com 


info@beni.se"
  ["to"]=>
  string(12) "info@beni.se"
  ["headers"]=>
  string(54) "From: test@hotmail.com 
Reply-To: test@hotmail.com 
"
}

0 个答案:

没有答案