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...........!