我在php中使用mail()函数。在这里,我有不同的形式,如注册,忘记密码等。实际上,当用户填写详细信息并提交表单时,我们将向用户发送一封电子邮件。所以为此我使用mail()函数。
但现在问题是由于这个mail()函数我得到错误了 500内部服务器错误
所以我在代码顶部添加了一个error_reporting('E_ALL')。然后它正常工作。现在我怀疑我们可以在生产中使用error_reporting('E_ALL')。现在我正致力于发展。在应用程序完成时,它曾经被转移到生产中。任何人都可以帮助解决这个问题。
我写的代码如下:
我包含的标题
$headers = "Reply-To: My Site <info@example.com>\r\n";
$headers .= "Return-Path: My Site <info@example.com>\r\n";
$headers .= "From: My Site <info@example.com>\r\n";
$headers .= "Organization: info@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
我写的邮件功能如下:
if(isset($_POST['sub']) && $_POST['sub']=="Submit")
{
$email=mysql_real_escape_string(trim($_POST['email']));
$email_fetch=$con->getdata("select * from mytable where email='{$email}'");
$rows=mysql_num_rows($email_fetch);
if($rows==0)
{
echo '<script> alert("Email Id Not Registered With Us.") </script>';
}
else
{
function randomcode()
{
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789";
$i = 0;
$vcode = '' ;
while($i < 7)
{
$num = mt_rand(0,61);
$tmp = substr($chars, $num, 1);
$vcode = $vcode . $tmp;
$i++;
}
return $vcode;
}
$msg=randomcode();
$secure_msg=md5($msg);
$update_pass=$con->setdata("update mytable set pass='$secure_msg' where email='{$email}'");
$user_subject='Your New Password';
$user_message='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Example</title>
<!-- <link rel="stylesheet" type="text/css" href="stylesheets/email.css"/> -->
</head>
<body bgcolor="#FFFFFF">
<table style="width:100%;" bgcolor="#999999">
<tr>
<td></td>
<td>
<div style="padding:15px;max-width:600px;margin:0 auto;display:block;">
<table style="width:100%;" bgcolor="#999999">
<tr>
<td style="padding:15px;"><img src="http://www.example.com/images/logo.jpg"/></td>
</tr>
</table>
</div>
</td>
<td></td>
</tr>
</table>
<table style="width: 100%;">
<tr>
<td></td>
<td style="display:block!important;max-width:600px!important;margin:0 auto!important;clear:both!important;" bgcolor="#FFFFFF">
<div style="padding:15px;max-width:600px;margin:0 auto;display:block;">
<table style="width:100%;">
<tr>
<td>
<h3>Dear User,</h3>
<p>Your password was reset at <a style="color: #2BA6CB;" href=http://www.example.com target=_blank>www.example.com</a>
</p>
<p style="padding:15px;background-color:#ECF8FF;margin-bottom: 15px;">
New password is '.$msg.'
</p>
<table style="background-color:#ebebeb;font-size:18px;line-height:19px;font-family: Helvetica, Arial, sans-serif; font-weight:normal;" width="100%">
<tr>
<td>
<table align="left" style="width: 200px;float:left;">
<tr>
<td style="padding-left: 10px;">
<h5 class="">Connect with Us:</h5>
<p class=""><a href="#" style="padding: 3px 7px;font-size:12px;margin-bottom:10px;text-decoration:none;color: #FFF;font-weight:bold;display:block;text-align:center;background-color: #3B5998!important;">Facebook</a> <a href="#" style="padding: 3px 7px;font-size:12px;margin-bottom:10px;text-decoration:none;color: #FFF;font-weight:bold;display:block;text-align:center;background-color: #1daced!important;">Twitter</a> <a href="#" style="padding: 3px 7px;font-size:12px;margin-bottom:10px;text-decoration:none;color: #FFF;font-weight:bold;display:block;text-align:center;background-color: #DB4A39!important;">Google+</a></p>
</td>
</tr>
</table>
<table align="right" style="width: 300px;float:right;">
<tr>
<td>
<h5 class="">Contact Info:</h5>
<p>Phone: <strong>123.456.7890</strong><br/>
Email: support@example.com</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</td>
<td></td>
</tr>
</table>
</body>
</html>
';
$mailto_user=mail($email, $user_subject, $user_message, $headers);
var_dump($mailto_user);
if($mailto_user)
{
echo '<script> alert("A New Password Is Sent To Your Email Id") </script>';
//header('location: example-signin.php');
}
}
}
请检查一下,让我知道.....
提前致谢...........!