无法处理请求错误500 php电子邮件

无法处理请求错误500 php电子邮件,php,arrays,Php,Arrays,编辑*感谢到目前为止的输入。我下载了javabeans,这对消除充斥我代码的所有小错误是一个很大的帮助。我已经让它几乎完全工作,除了一个部分 //Part numbers, if any $partNumbers = range(1,12); $part =array(); foreach($partNumbers as $value){ $part[$value] = 0; if(!empty($_POST['partnumber'.$value])){ $p

编辑*感谢到目前为止的输入。我下载了javabeans,这对消除充斥我代码的所有小错误是一个很大的帮助。我已经让它几乎完全工作,除了一个部分

//Part numbers, if any

$partNumbers = range(1,12);
$part =array();
foreach($partNumbers as $value){
    $part[$value] = 0;
    if(!empty($_POST['partnumber'.$value])){
        $part[$value] = $_POST['partnumber'.$value];
    }
}
//Check for part numbers
if($part[1] && $part[2]  && $part[3] && $part[4] && $part[5] && $part[6] && $part[7] && $part[8] && $part[9] && $part[10] && $part[11] && $part[12] ="0")
    {
    $email_body .= "No part numbers where listed.\r\n\r\n";
}
else{
     $email_body .= "Part numbers listed:\r\n";
     foreach( $partNumbers as $value){
         if($part[$value] !="0"){
             $email_body .="{$part['$value']}\r\n";}
      }
}
这将返回else语句中的“列出的零件号:”行、是否填充了none 1和/或所有零件号字段

*编辑

所以我一直在做我们网站的报价请求页面,这是一种电子邮件格式的表单。(站点=>>)。当我去提交表单时,我得到了“无法处理请求”错误。我知道我的网站可以发送电子邮件,在我透露代码之前,我成功地进行了一些小测试。我认为这个错误应该在php文件中的某个地方,该文件用于生成电子邮件。我最好的猜测是,它发生在将所有数据从存储阵列传输到电子邮件正文的过程中

另外,感谢您阅读和/或提供有关设计最佳实践的任何信息,或者我在哪里出错了

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
if(!isset($_POST['submit']))
{
    //This page should not be accessed directly. Need to submit the form.
    echo "error; you need to submit the form!";
}
//base customer input

$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$visitor_email = $_POST['email'];


//Validate first
if(empty($fname)||empty($visitor_email)||empty($lname)) 
{
    echo "Name and email are mandatory!";
    exit;
}

if(IsInjected($visitor_email))
{
    echo "Bad email value!";
    exit;
}

//Add base info
$fields = array(
    'phone' => 'phonenumber',
    'fax' => 'faxnumber',
    'web' => 'website',
    'company' => 'company',
    'street' => 'street',
    'city' => 'city',
    'state' => 'state',
    'zip' => 'zipcode',
    'description' => 'description'  
    );
$baseinfo = array();

foreach($fields as $key => $field){
    $baseinfo[$key] = "0";
    if(!empty($_POST[$field])){
        $baseinfo[$key] = $_POST[$field];}
    };  


//Part numbers, if any

$partNumbers = range(1,12);
$part =array();
foreach($partNumbers as $value){
    $part[$value] = 0;
    if(!empty($_POST['partnumber'.$value])){
        $part[$value] = $_POST['partnumber'.$value];
    };
};

//fixture fields

$fixtureFields = array(
    'type' => 'machinetype',
    'othertype' => 'othermachine',
    'nest' => 'nestmaterial',
    'special' => 'fixtureneeds',
    'movement' => 'fixturemovement'
    'other' => 'fotherneeds');
$fixturetooling = array();

foreach($fixtureFields as $key => $field){
    $fixturetooling[$key] = "0";
    if($_POST[$field] != 0 || !empty([$_POST[$field])){
        $fixturetooling[$key] = $_POST[$field];
    };    
};

//Horn Fields

$hornFields = array(
    'material' => 'hornmaterial',
    'finish' => 'hornfinish',
    'frequency' => 'hornfrequency',
    'shape' => 'hornshape'
    'special' => 'specialneeds',
    'facedim' => 'facedim',
    'basedim' => 'basedim',
    'facediameter' => 'facediameter',
    'basediameter' => 'basediameter',
    'stud' => 'studsize'
    'other' => 'hotherneeds'); 

$horntooling = array();

foreach($hornFields as $key => $field){
    $horntooling[$key] = "0";
    if($_POST[$field] != 0 || !empty([$_POST[$field])){
        $horntooling[$key] = $_POST[$field];
    };

}; 

//Begin formatting email 


$email_from = 'Sales@TomanThermoSonics.com';

$email_subject = "Quote Request from $fname $lname";

//body of email

$email_body = "$fname $lname has requested a quote.\r\n";
$email_body .= "\r\n";

//Check for description
if($baseinfo['description'] !="0")
    {
    $email_body .= "Description of Needs: \r\n\r\n";
    $email_body .= "$baseinfo['description']\r\n\r\n";
    }
    else{
          $email_body .= "No description was provided\r\n\r\n";
          }


//Check for part numbers
if($part[1] && $part[1] && $part[2] && $part[1] && $part[3] && $part[4] && $part[5] && $part[6] && $part[7] && $part[8] && $part[9] && $part[10] && $part[11] && $part[12] ="0")
    {
    $email_body .= "No part numbers where listed.\r\n\r\n";
}
else{
     $email_body .= "Part numbers listed:\r\n";
     foreach( $part as $value){
         if(value !="0"){
             $email_body .="$value\r\n";};
      };
};

$email_body .= "\r\n\r\n";

//Provide Fixture Info
$email_body .="Fixture Info: \r\n";





switch(!="0"){
        case $fixturetooling['type']:
              @email_body .= "Fixture Type: $fixturetooling[type]\r\n";            
        case $fixturetooling['othertype']:
              @email_body .= "Fixture Type: $fixturetooling[type]\r\n";            
        case $fixturetooling['nest']:
              @email_body .= "Nest material: $fixturetooling[type]\r\n";               
        case $fixturetooling['special']:
              @email_body .= "Special needs: $fixturetooling[type]\r\n";               
        case $fixturetooling['movement']:
              @email_body .= "Fixture movement: $fixturetooling[type]\r\n";            
        case $fixturetooling['other']:
              @email_body .= "Other needs: $fixturetooling[type]\r\n";
               }
$email)body .="\r\n\r\n";
$email_body .="Horn Info: \r\n";
//Provide UltrasonicHorn Info
switch(!="0"){
              case $horntooling['material']:
                   @email_body .= "Type of horn material: $horntooling['material']\r\n";
              case $horntooling['finish']:
                   @email_body .= "Horn finish: $horntooling['finish']\r\n";
              case $horntooling['frequency']:
                   @email_body .= "Horn frequency: $horntooling['frequency']\r\n";
              case $horntooling['shape']:
                   @email_body .= "Horn shape: $horntooling['shape']\r\n";
              case $horntooling['facedim']:
                   @email_body .= "Horn face Length x Width: $horntooling['facedim']\r\n";
              case $horntooling['basedim']:
                   @email_body .= "Horn base Length x Width: $horntooling['basedim']\r\n";
              case $horntooling['facediameter']:
                   @email_body .= "Horn face diameter: $horntooling['facediameter']\r\n";
              case $horntooling['basediameter']:
                   @email_body .= "Horn base diameter: $horntooling['basediameter']\r\n";
              case $horntooling['stud']:
                   @email_body .= "Stud size: $horntooling['stud']\r\n";
              case $horntooling['other']:
                   @email_body .= "Other horn needs: $horntooling['other']\r\n";

              }
$email_body .= "\r\n\r\n";

$email_body .="Customer Info";
$email_body ."Name: $fname $lname\r\n";
$email_body .="Company: $baseinfo['company']\r\n";
$email_body .="Email Address: $email\r\n";
$email_body .="Phone number: $baseinfo['phone']\r\n";
$email_body .="Fax number: $baseinfo['fax']\r\n";   
$email_body .="Address:\r\n $baseinfo['street']\r\n";
$email_body .="$baseinfo['city'], $baseinfo['state'] $baseinfo['zip']\r\n"; 










$to = "sales@tomanthermosonics.com";//<== update the email address
$headers = "From: $email_from \r\n";

$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');


// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}

?>

使用一串if语句或foreach是否更好?

您的PHP有很多错误:-

第68、85和91行

'movement' => 'fixturemovement'
'shape' => 'hornshape'
'stud' => 'studsize'
行尾缺少逗号

第74行和第98行

if($_POST[$field] != 0 || !empty([$_POST[$field])){
if($_POST[$field] != 0 || !empty([$_POST[$field])){
您的空函数中有一个额外的

第120行

$email_body .= "$baseinfo['description']\r\n\r\n";
变量需要用大括号“{}”括起来


老实说,我已经停在这里了,因为大多数问题都是同样的问题。正如评论中的人所指出的,这些实际上是任何PHP IDE在您开始测试代码之前都应该能够为您发现的非常简单的错误。您应该使用一个,因为它将使您的生活更加轻松您的代码中有很多错误。首先,您的数组有问题。
$fixtureFields,$hornFields
您忘了添加

,

然后,您必须更换它:

$email_body .= "$baseinfo['description']\r\n\r\n";
致:

然后,你必须修正你的陈述:


祝你好运!

500错误:检查日志我相信$hormFields数组中的“studsize”后面缺少一个逗号。请始终检查服务器错误日志,以了解500错误的原因。但是您的代码中有很多语法错误。请使用适当的IDE为您突出显示语法错误。@Dexter0015缺少的不仅仅是这个错误。@Dexter0015ng逗号。还有其他一些逗号丢失,括号不匹配,switch语句错误……这只是开始。@aynber,你说得对,我承认我已经停止了搜索。谢谢,我找到了一个沙盒,发现了你指出的大部分错误。发布代码图像不是一个好主意。最好只发布代码,而不发布它自己
$email_body .= "$baseinfo['description']\r\n\r\n";
$email_body .= $baseinfo['description']."\r\n\r\n";