Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的PHP脚本有什么问题?_Php_Arrays_If Statement - Fatal编程技术网

我的PHP脚本有什么问题?

我的PHP脚本有什么问题?,php,arrays,if-statement,Php,Arrays,If Statement,我希望这个php脚本首先决定是否应该发送以下电子邮件,所有这些电子邮件都使用从另一个html文件中的表单接收的数据。目前,我真的不知道我在用php做什么,也不知道从哪里开始。为了完成任务,我希望此人正确识别图片并将其与预先分配的密码相匹配。一旦他们做到了这一点,将发送2封电子邮件。我将如何格式化此文件 我在Ian和Thomaselis的帮助下调整了代码(感谢您的见解),但是,当我在表单上单击submit时,它只会将我带到php文件,并显示一个空白屏幕。我做错了什么。谢谢你的帮助:) 您可以更改以

我希望这个php脚本首先决定是否应该发送以下电子邮件,所有这些电子邮件都使用从另一个html文件中的表单接收的数据。目前,我真的不知道我在用php做什么,也不知道从哪里开始。为了完成任务,我希望此人正确识别图片并将其与预先分配的密码相匹配。一旦他们做到了这一点,将发送2封电子邮件。我将如何格式化此文件

我在Ian和Thomaselis的帮助下调整了代码(感谢您的见解),但是,当我在表单上单击submit时,它只会将我带到php文件,并显示一个空白屏幕。我做错了什么。谢谢你的帮助:)


您可以更改以下内容

$password1 = '2Vd27VFfkK' ;
$password2 = 'MjgxfNA5Qn' ;
$password3 = 'tg3K3GhS6W' ;
$password4 = 'n2m6GHfVSK' ;
$password5 = 'RTxqN5euFX' ;
$password6 = 'AJzsWwES6D' ;
$password7 = '24hAgsHuW3' ;
$password8 = 'xHzvW9kyFk' ;
$password9 = 'CyXH7VRhyp' ;
$password10 = 'QshfjUn75Z' ;

if $usrpassword == $password1 || $usrpassword == $password2 || $usrpassword == $password3 || $usrpassword == $password4 || $usrpassword == $password5 || $usrpassword == $password6 ||$usrpassword == $password7 || $usrpassword == $password8 || $usrpassword == $password9 || $usrpassword == $password10


另一种选择是将邮件包装在函数中,然后使用switch语句

switch($_REQUEST['usrpassword']){
case '2Vd27VFfkK':
    mailFunction();
    break;
case 'MjgxfNA5Qn':
    mailFunction();
    break;
case 'tg3K3GhS6W':
    mailFunction();
    break;
case 'n2m6GHfVSK':
    mailFunction();
    break;
case 'RTxqN5euFX':
    mailFunction();
    break;
case 'AJzsWwES6D':
    mailFunction();
    break;
case '24hAgsHuW3':
    mailFunction();
    break;
case 'xHzvW9kyFk':
    mailFunction();
    break;
case 'CyXH7VRhyp':
    mailFunction();
    break;
case 'QshfjUn75Z':
    mailFunction();
    break;
default:
    //Do something to handle invalid passwords here
} 

function mailFunction(){
$to1 = $_REQUEST['usremail'] ;
$subject1 = "Joining"; 
$email = "noreply@jones.org.au" ; 
$name = $_REQUEST['name'] ;
$message1 = "
** This is an automated email, please do not reply **

Hello $name,

Kind regards.
" ; 
$headers = "From: Recruiting";
$sent = mail($to1, $subject1, $message1, $headers) ;
if($sent){
        print "Your mail was sent successfully";
}    
else{
    print "We encountered an error sending your submission. Please refresh the page to try again.";
}
$to2 = "a@b.com" ;
$subject = "Signup Forms Requested" ; 
$from = $_REQUEST['name'] ;
$usremail = $_REQUEST['usremail'] ;
$comment = $_REQUEST['comment'] ;
$email = "noreply@jones.org.au" ; 
$message2 = "
** This is an automated email, please do not reply **

 Hello Administration Officer,

 The following email is to advise you that $from submitted a request for sign up forms.
 The email submitted was: $usremail

 They have recieved the required documents and have included the following comment in their submission:

 $comment

 Regards,
" ; 
$headers = "From: $email"; 
$sent = mail($to2, $subject2, $message2, $headers) ; 
if($sent){
    header( 'Location: http://example.com' ) ; 
}
else{
    print "We encountered an error sending your submission."; 
    header( 'Location: http://404sqn.aafc.org.au/joinus.html' ) ;
} 
}
请参阅PHP开关手册

虽然我同意@ian的观点,因为数组更易于管理。在这种情况下,您仍然可以将邮件程序包装在函数中,然后只需:

if(in_array($usrpassword, $passwords)){
    mailFunction();
}
else{
    //Handle invalid passwords here
}

有没有理由在if检查中没有“(”,“)”?您应该使用SwiftMailer或类似的库来帮助防止电子邮件注入。不确定,但它在我的原始代码中,仍然不起作用。只是显示一个空白屏幕。很抱歉不够清晰。我试图做的是在输入正确密码的条件下从表单发送数据。此时,当我点击html表单中的submit时,它将我重定向到php并显示一个空白屏幕,而不发送电子邮件。非常感谢您的帮助,非常感谢。只是好奇一下使用switch语句的逻辑,当所有结果都相同(mailFunction)时,如果使用的密码调用不同的函数,那么切换将更有意义。非常正确。这就是为什么我同意伊恩的答案。只是想提供另一个选项,以便OP能够更多地了解PHP及其可用函数。
switch($_REQUEST['usrpassword']){
case '2Vd27VFfkK':
    mailFunction();
    break;
case 'MjgxfNA5Qn':
    mailFunction();
    break;
case 'tg3K3GhS6W':
    mailFunction();
    break;
case 'n2m6GHfVSK':
    mailFunction();
    break;
case 'RTxqN5euFX':
    mailFunction();
    break;
case 'AJzsWwES6D':
    mailFunction();
    break;
case '24hAgsHuW3':
    mailFunction();
    break;
case 'xHzvW9kyFk':
    mailFunction();
    break;
case 'CyXH7VRhyp':
    mailFunction();
    break;
case 'QshfjUn75Z':
    mailFunction();
    break;
default:
    //Do something to handle invalid passwords here
} 

function mailFunction(){
$to1 = $_REQUEST['usremail'] ;
$subject1 = "Joining"; 
$email = "noreply@jones.org.au" ; 
$name = $_REQUEST['name'] ;
$message1 = "
** This is an automated email, please do not reply **

Hello $name,

Kind regards.
" ; 
$headers = "From: Recruiting";
$sent = mail($to1, $subject1, $message1, $headers) ;
if($sent){
        print "Your mail was sent successfully";
}    
else{
    print "We encountered an error sending your submission. Please refresh the page to try again.";
}
$to2 = "a@b.com" ;
$subject = "Signup Forms Requested" ; 
$from = $_REQUEST['name'] ;
$usremail = $_REQUEST['usremail'] ;
$comment = $_REQUEST['comment'] ;
$email = "noreply@jones.org.au" ; 
$message2 = "
** This is an automated email, please do not reply **

 Hello Administration Officer,

 The following email is to advise you that $from submitted a request for sign up forms.
 The email submitted was: $usremail

 They have recieved the required documents and have included the following comment in their submission:

 $comment

 Regards,
" ; 
$headers = "From: $email"; 
$sent = mail($to2, $subject2, $message2, $headers) ; 
if($sent){
    header( 'Location: http://example.com' ) ; 
}
else{
    print "We encountered an error sending your submission."; 
    header( 'Location: http://404sqn.aafc.org.au/joinus.html' ) ;
} 
}
if(in_array($usrpassword, $passwords)){
    mailFunction();
}
else{
    //Handle invalid passwords here
}