2014-01-16 47 views
-2

我试图运行这个脚本,但它抛出500 INTERNAL ERROR PROBLEM,虽然代码不会引发任何错误。
该脚本引发内部服务器500错误,但是当我删除第二个$user mail,它工作正常。我想发送一个确认邮件以及成功提交并重定向到谢谢page.I希望我已正确编码。帮助,如果你的PHP代码有致命错误,但错误显示关闭显示邮件内部服务器错误()

<?php 
//output variables 

$output=""; 

$host="databasehost.com"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="databasename"; // Database name 
$tbl_name="tablename"; // Table name 

// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

$result = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="property-value" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result1 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="firstname" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result2 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="lastname" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result3 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="from_email" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result4 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="houseflat-nos" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result5 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="street" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result6 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="towncity" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result7 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="postcode" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result8 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="telephone" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result9 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="outstanding-mortgage" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

//print values to screen 
while ($row = mysql_fetch_assoc($result)) { 
    //echo $row['ID']; 
    $output = $row['field_value']; 
    $percentage = 75; 

    $prelim = ($percentage/100) * $output; 
} 

while ($row = mysql_fetch_assoc($result1)) { 
    //echo $row['ID']; 
    $output1 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result2)) { 
    //echo $row['ID']; 
    $output2 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result3)) { 
    //echo $row['ID']; 
    $output3 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result4)) { 
    //echo $row['ID']; 
    $output4 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result5)) { 
    //echo $row['ID']; 
    $output5 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result6)) { 
    //echo $row['ID']; 
    $output6 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result7)) { 
    //echo $row['ID']; 
    $output7 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result8)) { 
    //echo $row['ID']; 
    $output8 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result9)) { 
    //echo $row['ID']; 
    $output9 = $row['field_value']; 
} 

// Free the resources associated with the result set 
// This is done automatically at the end of the script 
mysql_free_result($result,$result1,$result2,$result3,$result4,$result5,$result6,$result7,$result8,$result9); 

// References to the name values in your HTML form 
$field_property1 = $_POST['typeofproperty']; 
$field_property2 = $_POST['bedrooms']; 
$field_property3 = $_POST['bathrooms']; 
$field_property4 = $_POST['toilets']; 
$field_property5 = $_POST['reception']; 
$field_property6 = $_POST['garage']; 
$field_property7 = $_POST['garden']; 
$field_property8 = $_POST['generalCondition']; 
$field_property9 = $_POST['builtYear']; 
$field_property10 = $_POST['centralHeating']; 
$field_property11 = $_POST['doubleGlazing']; 
$field_property12 = $_POST['structure']; 
$field_property13 = $_POST['association']; 
$field_property14 = $_POST['inblock']; 
$field_property15 = $_POST['freehold']; 
$field_property16 = $_POST['yearsleft']; 
$field_property17 = $_POST['why']; 
$field_property18 = $_POST['when']; 
$field_property19 = $_POST['other']; 
$field_property20 = $_POST['how']; 
$field_property21 = $_POST['howLong']; 
$field_property22 = $_POST['workforproperty']; 
$field_property23 = $_POST['uniquefeatures']; 
$field_property24 = $_POST['anythingelse']; 

$user = "$output3"; 
$usersubject = "Thank You"; 
$userheaders = "From: [email protected]\n"; 
$usermessage = "Thank You for your Enquiry. A member of staff will be in contact shortly to discuss your requirements."; 

// Since some emails are unknown, I reccomend using a known email sender to avoid messages to go directly to the SPAM folder 
$field_sender = ' [email protected]'; 

// In which address would you like to recieve the messages? Would you like a custom Subject for each? 
$mail_to = ' [email protected]'; 
$subject = '[QUALIFIED LEAD] Enuiry '; 

// This builds the message 
$body_message = 'From: '.$output1."\n"; 
$body_message .= 'Phone: '.$output8."\n"; 
$body_message .= 'Email: '.$output3."\n\n"; 
$body_message .= 'Flat: '.$output4."\n"; 
$body_message .= 'Street: '.$output5."\n"; 
$body_message .= 'City: '.$output6."\n"; 
$body_message .= 'ZIP: '.$output7."\n\n"; 
$body_message .= 'Property Value: '.$output."\n\n"; 
$body_message .= 'Offer Value: '.$prelim."\n"; 
$body_message .= 'Outstanding Value: '.$output9."\n\n"; 
$body_message .= 'Type of Property: '.$field_property1."\n"; 
$body_message .= 'Number of Bedrooms: '.$field_property2."\n"; 
$body_message .= 'Number of Bathrooms: '.$field_property3."\n"; 
$body_message .= 'Number of Separate Toilets: '.$field_property4."\n"; 
$body_message .= 'Number of Reception Rooms: '.$field_property5."\n"; 
$body_message .= 'Garage: '.$field_property6."\n"; 
$body_message .= 'Garden: '.$field_property7."\n"; 
$body_message .= 'General Condition of Property: '.$field_property8."\n"; 
$body_message .= 'Property Built In: '.$field_property9."\n"; 
$body_message .= 'Central Heating: '.$field_property10."\n"; 
$body_message .= 'Double Glazing: '.$field_property11."\n"; 
$body_message .= 'Structure of Property: '.$field_property12."\n"; 
$body_message .= 'Ex-Council/Housing association: '.$field_property13."\n\n"; 
$body_message .= 'Property in a Block: '.$field_property14."\n"; 
$body_message .= 'Freehold/Leasehold: '.$field_property15."\n"; 
$body_message .= 'Years of Leashold Left: '.$field_property16."\n"; 
$body_message .= 'Reason for Quick Sale: '.$field_property17."\n\n"; 
$body_message .= 'How soon: '.$field_property18."\n\n"; 
$body_message .= 'Any Loans Secured on Property: '.$field_property19."\n\n"; 
$body_message .= 'How Much Loan Secured: '.$field_property20."\n\n"; 
$body_message .= 'Property Currently in Market: '.$field_property21."\n\n"; 
$body_message .= 'For How Long: '.$field_property22."\n\n"; 
$body_message .= 'Any Work Done: '.$field_property23."\n\n"; 
$body_message .= 'Any Unique Feature: '.$field_property24."\n\n"; 
$body_message .= 'Additional Details to Buyer: '.$field_property25."\n\n"; 


// Email headers 'From' a known email address to avoid being taken as SPAM and 'Reply-to' the one that filed in the form 
$headers = 'From: '.$field_sender."\r\n"; 
$headers  .= 'Reply-To: '.$field_email."\r\n"; 

// Status, builds whole email structure 
mail($mail_to, $subject, $body_message, $headers); 

mail($user,$usersubject,$usermessage,$userheaders); 

if(mail($mail_to, $subject, $body_message, $headers)){ 
header("Location: http://websitename.com/thankyou-page/); 
}else{ 
header("Location: http://websitename.com"); 
} 
exit; 


?> 

<?php 
// close connection 
mysql_close(); 
?> 
+2

A“500内部服务器错误”状态码(或者空白页)意味着你的脚本抛出一个错误,但你的避风港未配置PHP来显示错误消息。这是你在进一步研究之前需要解决的问题;没有错误消息的帮助,就不可能正确编码。这里有一个[简要说明](http://stackoverflow.com/a/5680885/13508)。 –

+0

我建议你看到apache日志,你可以得到确切的错误 – Freak

+0

感谢您的快速响应...你的意思是我添加代码来显示错误...我没有访问php.ini或htaccess文件。还有别的办法吗? –

回答

0

感谢所有的辉煌回应家伙! (ÁlvaroG. Vicario,怪胎,Bart Friederichs,Bart Friederichs,不要忘记哈桑)

它终于被排序。请在下面找到的是工作代码:(随意,如果你想修改它)

<?php 

ini_set('display_errors', 1); 

//output variables 

$output=""; 

$host="databasehost.com"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="databasename"; // Database name 
$tbl_name="tablename"; // Table name 

// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

$result = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="property-value" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result1 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="firstname" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result2 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="lastname" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result3 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="from_email" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result4 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="houseflat-nos" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result5 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="street" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result6 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="towncity" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result7 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="postcode" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result8 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="telephone" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

$result9 = mysql_query('SELECT `field_value` FROM `tablename` WHERE `field_name`="outstanding-mortgage" ORDER BY `submit_time` DESC LIMIT 1') or die('Invalid query: ' . mysql_error()); 

//print values to screen 
while ($row = mysql_fetch_assoc($result)) { 
    //echo $row['ID']; 
    $output = $row['field_value']; 
    $percentage = 75; 

    $prelim = ($percentage/100) * $output; 
} 

while ($row = mysql_fetch_assoc($result1)) { 
    //echo $row['ID']; 
    $output1 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result2)) { 
    //echo $row['ID']; 
    $output2 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result3)) { 
    //echo $row['ID']; 
    $output3 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result4)) { 
    //echo $row['ID']; 
    $output4 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result5)) { 
    //echo $row['ID']; 
    $output5 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result6)) { 
    //echo $row['ID']; 
    $output6 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result7)) { 
    //echo $row['ID']; 
    $output7 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result8)) { 
    //echo $row['ID']; 
    $output8 = $row['field_value']; 
} 

while ($row = mysql_fetch_assoc($result9)) { 
    //echo $row['ID']; 
    $output9 = $row['field_value']; 
} 

// Free the resources associated with the result set 
// This is done automatically at the end of the script 
mysql_free_result($result,$result1,$result2,$result3,$result4,$result5,$result6,$result7,$result8,$result9); 

// References to the name values in your HTML form 
$field_property1 = $_POST['typeofproperty']; 
$field_property2 = $_POST['bedrooms']; 
$field_property3 = $_POST['bathrooms']; 
$field_property4 = $_POST['toilets']; 
$field_property5 = $_POST['reception']; 
$field_property6 = $_POST['garage']; 
$field_property7 = $_POST['garden']; 
$field_property8 = $_POST['generalCondition']; 
$field_property9 = $_POST['builtYear']; 
$field_property10 = $_POST['centralHeating']; 
$field_property11 = $_POST['doubleGlazing']; 
$field_property12 = $_POST['structure']; 
$field_property13 = $_POST['association']; 
$field_property14 = $_POST['inblock']; 
$field_property15 = $_POST['freehold']; 
$field_property16 = $_POST['yearsleft']; 
$field_property17 = $_POST['why']; 
$field_property18 = $_POST['when']; 
$field_property19 = $_POST['other']; 
$field_property20 = $_POST['how']; 
$field_property21 = $_POST['howLong']; 
$field_property22 = $_POST['workforproperty']; 
$field_property23 = $_POST['uniquefeatures']; 
$field_property24 = $_POST['anythingelse']; 

$user = "$output3"; 
$usersubject = "Thank You"; 
$userheaders = "From: [email protected]\n"; 
$usermessage = "Thank You for your Enquiry. A member of staff will be in contact shortly to discuss your requirements."; 

// Since some emails are unknown, I reccomend using a known email sender to avoid messages to go directly to the SPAM folder 
$field_sender = ' [email protected]'; 

// In which address would you like to recieve the messages? Would you like a custom Subject for each? 
$mail_to = ' [email protected], '.$user; 
$subject = '[QUALIFIED LEAD] Enuiry '; 

// This builds the message 
$body_message = 'From: '.$output1."\n"; 
$body_message .= 'Phone: '.$output8."\n"; 
$body_message .= 'Email: '.$output3."\n\n"; 
$body_message .= 'Flat: '.$output4."\n"; 
$body_message .= 'Street: '.$output5."\n"; 
$body_message .= 'City: '.$output6."\n"; 
$body_message .= 'ZIP: '.$output7."\n\n"; 
$body_message .= 'Property Value: '.$output."\n\n"; 
$body_message .= 'Offer Value: '.$prelim."\n"; 
$body_message .= 'Outstanding Value: '.$output9."\n\n"; 
$body_message .= 'Type of Property: '.$field_property1."\n"; 
$body_message .= 'Number of Bedrooms: '.$field_property2."\n"; 
$body_message .= 'Number of Bathrooms: '.$field_property3."\n"; 
$body_message .= 'Number of Separate Toilets: '.$field_property4."\n"; 
$body_message .= 'Number of Reception Rooms: '.$field_property5."\n"; 
$body_message .= 'Garage: '.$field_property6."\n"; 
$body_message .= 'Garden: '.$field_property7."\n"; 
$body_message .= 'General Condition of Property: '.$field_property8."\n"; 
$body_message .= 'Property Built In: '.$field_property9."\n"; 
$body_message .= 'Central Heating: '.$field_property10."\n"; 
$body_message .= 'Double Glazing: '.$field_property11."\n"; 
$body_message .= 'Structure of Property: '.$field_property12."\n"; 
$body_message .= 'Ex-Council/Housing association: '.$field_property13."\n\n"; 
$body_message .= 'Property in a Block: '.$field_property14."\n"; 
$body_message .= 'Freehold/Leasehold: '.$field_property15."\n"; 
$body_message .= 'Years of Leashold Left: '.$field_property16."\n"; 
$body_message .= 'Reason for Quick Sale: '.$field_property17."\n\n"; 
$body_message .= 'How soon: '.$field_property18."\n\n"; 
$body_message .= 'Any Loans Secured on Property: '.$field_property19."\n\n"; 
$body_message .= 'How Much Loan Secured: '.$field_property20."\n\n"; 
$body_message .= 'Property Currently in Market: '.$field_property21."\n\n"; 
$body_message .= 'For How Long: '.$field_property22."\n\n"; 
$body_message .= 'Any Work Done: '.$field_property23."\n\n"; 
$body_message .= 'Any Unique Feature: '.$field_property24."\n\n"; 
$body_message .= 'Additional Details to Buyer: '.$field_property25."\n\n"; 


// Email headers 'From' a known email address to avoid being taken as SPAM and 'Reply-to' the one that filed in the form 
$headers = 'From: '.$field_sender."\r\n"; 
$headers  .= 'Reply-To: '.$field_email."\r\n"; 

// Status, builds whole email structure 


if(mail($mail_to, $subject, $body_message, $headers)){ 
header("Location: http://websitename.com/thankyou-page/"); 
}else{ 
header("Location: http://websitename.com"); 
} 
exit; 


?> 

<?php 
// close connection 
mysql_close(); 
?> 
0
change $user = "$output3"; to $user = $output3; 
+0

$ result3和$ output3应该是一个字符串无论如何(电子邮件地址),所以没有造成任何损害(只是几个浪费的周期)。 –

0

500内部服务器错误。你可以试试这个,看看错误本身,而不是500错误页面:

在你的PHP文件:

ini_set('display_errors', 1); 

您还可以检查Apache的错误日志,如果你有机会到他们。

0

如果您删除/注释掉第二个mail()调用,它会起作用吗?你知道你可以放置多个“to”地址并使用一个邮件(),不是吗?

$mail_to = ' [email protected], '.$user; 

我不确定前导空间是否会造成任何伤害(尝试删除它,如果没有其他作品)。现在,$user是合法的电子邮件地址吗?你打印出来检查它吗?

或者,您可以在标题中添加“cc:”电子邮件地址,如果您想将其发送给该人员。