我的PHP脚本有什么问题?

时间:2014-05-05 13:59:38

标签: php arrays if-statement

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

我已经用Ian和ThomasEliss的帮助调整了我的代码(谢谢你的见解),然而,当我点击我的表单上的提交时,它只是带我到php文件,显示一个空白屏幕。我究竟做错了什么。谢谢你的帮助:))

<?php 
$captcha = $_REQUEST['captcha'] ;
$passwords = array();
$passwords[] = '2Vd27VFfkK' ;
$passwords[] = 'MjgxfNA5Qn' ;
$passwords[] = 'tg3K3GhS6W' ;
$passwords[] = 'n2m6GHfVSK' ;
$passwords[] = 'RTxqN5euFX' ;
$passwords[] = 'AJzsWwES6D' ;
$passwords[] = '24hAgsHuW3' ;
$passwords[] = 'xHzvW9kyFk' ;
$passwords[] = 'CyXH7VRhyp' ;
$passwords[] = 'QshfjUn75Z' ;
if(in_array($usrpassword, $passwords)) {
 $to1 = $_REQUEST['usremail'] ;
 $subject1 = "Joining"; 
 $email = "me@email.com" ; 
 $name = $_REQUEST['name'] ;
 $message1 = "
** This is an automated email, please do not reply **

Hello $name,

This email has been sent because this email address was submitted to our site requesting signup documents. 
If this was not you please ignore this email.
If it was you follow the link below to receive the required documents.

If you have any other questions feel free to email our Administration Officer.

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 = "me@email.com" ;
 $subject = "Signup Forms Requested" ; 
 $from = $_REQUEST['name'] ;
 $usremail = $_REQUEST['usremail'] ;
 $comment = $_REQUEST['comment'] ;
 $email = "me@email.com" ; 
 $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

 If you have any questions or problems please email the Webmaster.

 Regards.

 email: me@email.com
" ; 
 $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."; }
}
else {
 {header( 'Location: http://example.com' ) ; }
}
?>

2 个答案:

答案 0 :(得分:1)

您可以更改以下内容

$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

$passwords = array();
$passwords[] = '2Vd27VFfkK' ;
$passwords[] = 'MjgxfNA5Qn' ;
$passwords[] = 'tg3K3GhS6W' ;
$passwords[] = 'n2m6GHfVSK' ;
$passwords[] = 'RTxqN5euFX' ;
$passwords[] = 'AJzsWwES6D' ;
$passwords[] = '24hAgsHuW3' ;
$passwords[] = 'xHzvW9kyFk' ;
$passwords[] = 'CyXH7VRhyp' ;
$passwords[] = 'QshfjUn75Z' ;

if(in_array($usrpassword, $passwords))

答案 1 :(得分:0)

另一种选择是将邮件包装在一个函数中,然后使用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开关手册http://www.php.net/manual/en/control-structures.switch.php

虽然我同意@ ian&#39; answer,因为数组更容易管理。在这种情况下,你仍然可以将邮件程序包装在一个函数中,然后只有:

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