2014-10-29 3 views
0

Когда я отправляю форму контакта php на локальном сервере xampp, показывая: «Мы не можем отправить электронное сообщение из-за некоторых технических проблем. Пожалуйста, попробуйте еще раз.' Просьба помочь, как исправить эту ошибку ..Ошибка при отправке почты на локальном сервере xampp

Вот мой PHP код

<?php 
session_start(); 
ini_set("display_errors",'0');//Display errors 
if($_POST['submit']) 
{ 
$key=substr($_SESSION['key'],0,5); 
//echo "key---------->".$key; 
$number = $_REQUEST['number']; 
//echo "number---------->".$number; 
if($number!=$key) { 
$error="<left><font color=\"red\"><b>Invalid Enter Code !</b></font></left>"; 
} 
else 
{ 
    $to = "[email protected]"; 

      $html_msg = ' 
      <html> 
       <head> 
        <title>test Services Enquiry Form</title> 
</head> 
    <body> 

    <table width="0%" align="center" cellpadding="5" cellspacing="0" style="border:2px solid #2964B0;"> 
     <tr> 
     <td colspan="3" align="center" bgcolor="#2763AF"><font color="#FFFFFF" size="3" face="Arial, Helvetica, sans-serif"><strong>test Services Enquiry Form</strong></font></td> 
     </tr> 
     <tr> 
     <td align="right"><font size=2 color=322147 face=Arial, Helvetica, sans-serif><b>Name</b></font></td> 
     <td><strong><font size=2 color=#2d557f face=verdena>:</font></strong></td> 
     <td><font size=2 color=#000000 face=verdena>'.$_POST['txtName'].'</font></td> 
     </tr> 

     <tr> 
     <td align="right"><font size=2 color=322147 face=Arial, Helvetica, sans-serif><b>Mobile</b></font></td> 
     <td><strong><font size=2 color=#2d557f face=verdena>:</font></strong></td> 
     <td><font size=2 color=#000000 face=verdena>'.$_POST['txtPhone'].'</font></td> 
     </tr> 

     <tr> 
     <td align="right"><font size=2 color=322147 face=Arial, Helvetica, sans-serif><b>Email</b></font></td> 
     <td><strong><font size=2 color=#2d557f face=verdena>:</font></strong></td> 
     <td><font size=2 color=#000000 face=verdena>'.$_POST['txtEmail'].'</font></td> 
     </tr> 

     <tr> 
     <td align="right"><font size=2 color=322147 face=Arial, Helvetica, sans-serif><b>Gross Income</b></font></td> 
     <td><strong><font size=2 color=#2d557f face=verdena>:</font></strong></td> 
     <td><font size=2 color=#000000 face=verdena>'.$_POST['txtIncome'].'</font></td> 
     </tr> 


     </table> 
    </body> 
        </html>'; 

    ini_set ("sendmail_from", "[email protected]"); 
    ini_set("SMTP","localhost"); 
    $subject="test Services Form : ".$_POST['txtName']; 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= "Content-type: text/html; charset=utf-8\r\n "; 
    $message .="Content-Transfer-Encoding: 7bit \r\n"; 
    $message=$html_msg; 
    $mailsent= mail($to,$subject,$message,$headers); 

    if($mailsent) 
    { 

    /*header("location:thanks.html");*/ 

    echo "<script language=javascript>;window.location=\"index.php\";alert(\"Thanks for filling the form. We will get in touch with you soon. \");</script>"; 




    /* $msg="<font color='#E7B376'>Thanks for submitting our booking form. 
<br>One of our representatives will get in touch with you soon.</font>";*/ 
    } 

    else 
    { 
    $msg="<span style='color:red;'>We are unable to send email due to some technical problems. Please try again.</span>"; 

    } 

} 
} 


?> 
+0

Что JavaScript, HTML, CSS должны делать с ошибкой на стороне сервера? – epascarello

+1

Вы не можете отправлять почту с localhost, по крайней мере, напрямую. http://stackoverflow.com/a/16837929/1745672 – Mihai

+0

Скорее всего, ваш локальный хост не настроил почтовый сервер, который необходим для отправки по электронной почте локально. – Typhomism

ответ

0

Вы должны настроить php.ini с SMTP данными вашей электронной почты.

Смотрите этот учебник по адресу: http://planetghost.com/send-emails-localhost-xampp-wamp-php

Не забудьте перезапустить сервер после изменения.

+0

Не могли бы вы подробно рассказать об этом из вашей ссылки, если ссылка мертвый? – Elias

Смежные вопросы