当我在本地xampp服务器中提交php联系表单时显示'由于某些技术问题,我们无法发送电子邮件。请再试一次。'请帮助解决此错误的方法..
这是我的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 = "test@gmail.com";
$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", "test@gmail.com");
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 :(得分:0)
您必须使用电子邮件的SMTP数据配置php.ini。
请参阅本教程:http://planetghost.com/send-emails-localhost-xampp-wamp-php
请勿忘记在更改后重新启动服务器。
答案 1 :(得分:0)
Ramakrishna我找到了解决问题的方法可能会对你有所帮助
PHP : send mail in localhost
http://rajeshstutorials.blogspot.in/2012/04/how-to-set-up-smtp-server-on-localhost.html