donglu5000 2016-02-03 05:40
浏览 26

在PHP中使用mail()函数时出现500内部服务器错误

I am working mail() function in php. Here I have different forms like register, forget password etc. Actually when user fill the details and submits the form we will send an email to the user. So for that I am using mail() function.

But now the problem is due to this mail() function I am getting the error as 500 Internal Server Error

So I add a error_reporting('E_ALL') at top of my code. Then it worked correctly. Now I have doubt that can we use error_reporting('E_ALL') in production. Now I am working on developing. It used to be moved to production when application will be completed. So can any one help how to solve this issue.

The following code I have written:

Headers I included

$headers = "Reply-To: My Site <info@example.com>
"; 
$headers .= "Return-Path: My Site <info@example.com>
"; 
$headers .= "From: My Site <info@example.com>
";
$headers .= "Organization: info@example.com
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-type: text/html;; charset=iso-8859-1
";
$headers .= "X-Priority: 3
";
$headers .= "X-Mailer: PHP". phpversion() ."
" ;

And Mail function I written is as follows:

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');
                        }
    }
}

Please check it and let me know.....

Thanks in advance...........!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c