编辑*感谢目前为止的输入。我下载了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语句中的“Part numbers Listed:”行,weather none 1和/或所有part number字段是否已填充。
*修改
所以我一直致力于我们的网站报价请求页面,这是一个电子邮件格式的表单。 (site =>> http://www.tomanthermosonics.com/form-page.html)。当我去提交表单时,我无法处理请求错误。我知道我的网站可以发送电子邮件,在我泄漏到代码之前,我成功完成了一些小测试。我认为错误必须在用于生成电子邮件的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;
}
}
?>
感谢您迄今为止的快速输入;我正在下载一个ide。我正在努力理解如何在这些情况下让switch语句评估为true。
我正在尝试将其更改为
switch(!"0")
case $somearray['somekey']:
我最好使用一串if语句或foreach吗?
答案 0 :(得分:0)
你的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";
变量需要用大括号括起来&#34; {}&#34;
说实话,我已经停在这里,因为大多数问题都是同一类问题。正如评论中的人们指出的那样,这些实际上是非常简单的错误,任何PHP IDE都应该能够在您开始测试代码之前为您提供帮助。你应该使用一个,因为它会让你的生活更容易在这样的问题。
答案 1 :(得分:0)
你的代码中有很多错误。首先,您忘记添加
数组$fixtureFields, $hornFields
时遇到问题
,
然后,你必须更换它:
$email_body .= "$baseinfo['description']\r\n\r\n";
要:
$email_body .= $baseinfo['description']."\r\n\r\n";
然后,您必须修复switch声明:
祝你好运!