开发者

Any suggestions on how to trouble shoot internal server error for an almost identical script?

On my site I have a contactUser.php that sends mail and a replyMail.php. I have put PHPMail on my contact user to send email notifications which is working great. When I put the same code chunk on my replyMail (which mail goes to the same place as the contact user mail,the inbox) that shares the same variables its giving me a internal server error. I have tried different GET vars as well as echoed die($vars) and echoed queries. Any ideas what the problem might be. Here is my code:

$prof = new User($_GET['id']);

$query = "SELECT `Email` FROM `Users` WHERE `id` = '" . $prof->id . "'";
$request = mysql_query($query,$connection) or die(mysql_error());
$result = mysql_fetch_array($request); 

$Email = $result['Email'];


$to = $Email;
$subject = "$auth->first_name $auth->last_name sent you a message";
$message = "$auth->first_name $auth->last_name sent you a message:<br /> <br /> <a href='http://www.blah.org/Inbox.php'>Click here to view</a><br /><br /> The Team";
$from = "blah<noreply@blah.org>";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=is开发者_JAVA技巧o-8859-1' . "\r\n";
$headers .= "From:$from";
mail($to, $subject, $message, $headers);


I really suggest wrapping it up into a function. From what you've posted, I get the sense that you have all the code in the global namespace, in which case any number of auto-prepends or includes could easily be messing with variables.

Something like:

// Function that accepts a user object and a database connection, then sends a notice email.
function email_message_notice($prof, $connection){
$query = "SELECT `Email` FROM `Users` WHERE `id` = '" . $prof->id . "'";
$request = mysql_query($query,$connection) or die(mysql_error());
$result = mysql_fetch_array($request); 

$Email = $result['Email'];

$to = $Email;
$subject = "$auth->first_name $auth->last_name sent you a message";
$message = "$auth->first_name $auth->last_name sent you a message:<br /> <br /> <a href='http://www.blah.org/Inbox.php'>Click here to view</a><br /><br /> The Team";
$from = "blah<noreply@blah.org>";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:$from";
$res = mail($to, $subject, $message, $headers);
return $res;
}


$prof = new User($_GET['id']);
$sent = email_message_notice($prof, $connection);

Since there's a database involved, this is untested code, so you'll want to test that it works and want to debug any further issues yourself, but otherwise it should be a good way to compartmentalize and share the code. If you're doing exactly the same thing in both scripts, you can just include the email_user function in a separate include.


Look into the server log. Should tell you what is wrong. Maybe file permissions.


Is that the whole script? I can't see anything there that could cause a 500 error. Can you post the whole page or a link to the source code of the whole page?

Is this a part of some loop or mass mailing that gets called repeatedly?

Is there no way to get hold of the Apache error logs? Only they will give you a definite answer what goes wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜