在本地xampp服务器发送邮件时发生错误
问题描述:
当我在本地xampp服务器上提交php联系表单时显示'由于某些技术问题,我们无法发送电子邮件。请再试一次。'请帮助如何解决这个错误..在本地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>";
}
}
}
?>
答
你必须与你的电子邮件的SMTP数据配置你的php.ini。
请参见本教程在:http://planetghost.com/send-emails-localhost-xampp-wamp-php
不要忘了更改后重新启动服务器。您的问题
+0
你能详细介绍你的链接在这里的教程,以防万一链接死? – Elias 2014-10-29 13:09:29
是什么的JavaScript,HTML,CSS有一个服务器端的错误呢? – epascarello 2014-10-29 12:27:57
您不能从本地主机发送邮件,至少不能直接发送邮件。 http://*.com/a/16837929/1745672 – Mihai 2014-10-29 12:31:37
机会是你的localhost没有设置邮件服务器,这是需要发送电子邮件本地 – Typhomism 2014-10-29 12:39:14