2017-05-13 1 views
0

이 문의 양식이 작동하지 않습니다. 누구든지 도와 드릴 수 있습니까? 추신 : 아무것도 PHP로 이해가foreach() (문의 양식)에 잘못된 인수가 제공되었습니다.

아래 연락처 양식 스크립트.

PHP 경고 : 당신이 (같은 개체 또는 배열) 배열 패스 라인 (54)이 기대에 줄에 htdocs에/박쥐/MailHandler.php에서 foreach는()에 대한 공급 잘못된 인수 (54)

<?php 
    $owner_email='[email protected]'; 
    //SMTP server settings 
    $host = 'smtp.site.com'; 
    $port = '25';//"587"; 
    $username = ''; 
    $password = ''; 

    $subject='A message from your site visitor '; 
    $user_email='';  
    $message_body=''; 
    $message_type='html'; 

    $max_file_size=50;//MB 
    $file_types='/(doc|docx|txt|pdf|zip|rar)$/'; 
    $error_text='something goes wrong'; 
    $error_text_filesize='File size must be less than'; 
    $error_text_filetype='Failed to upload file. This file type is not allowed. Accepted files types: doc, docx, txt, pdf, zip, rar.'; 

    // $private_recaptcha_key='6LeZwukSAAAAACmqrbLmdpvdhC68NLB1c9EA5vzU'; //localhost 


    $use_recaptcha=isset($_POST["recaptcha_challenge_field"]) and isset($_POST["recaptcha_response_field"]); 
    $use_smtp=($host=='' or $username=='' or $password==''); 
    $max_file_size*=1048576; 

    if($owner_email=='' || $owner_email=='#'){ 
     die('Attention, recipient e-mail is not set! Please define "owner_email" variable in the MailHanlder.php file.'); 
    } 

    if(preg_match('/^(127\.|192\.168\.)/',$_SERVER['REMOTE_ADDR'])){ 
     die('Attention, contact form will not work locally! Please upload your template to a live hosting server.'); 
    } 

    if($use_recaptcha){ 
     require_once('recaptchalib.php'); 
     $resp = recaptcha_check_answer ($private_recaptcha_key,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]); 
     if (!$resp->is_valid){ 
      die ('wrong captcha'); 
     } 
    } 

    if(isset($_POST['name']) and $_POST['name'] != ''){$message_body .= '<p>Visitor: ' . $_POST['name'] . '</p>' . "\n" . '<br>' . "\n"; $subject.=$_POST['name'];} 
    if(isset($_POST['email']) and $_POST['email'] != ''){$message_body .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n" . '<br>' . "\n"; $user_email=$_POST['email'];} 
    if(isset($_POST['state']) and $_POST['state'] != ''){$message_body .= '<p>State: ' . $_POST['state'] . '</p>' . "\n" . '<br>' . "\n";} 
    if(isset($_POST['phone']) and $_POST['phone'] != ''){$message_body .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n" . '<br>' . "\n";} 
    if(isset($_POST['fax']) and $_POST['fax'] != ''){$message_body .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n" . '<br>' . "\n";} 
    if(isset($_POST['message']) and $_POST['message'] != ''){$message_body .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";} 
    if(isset($_POST['stripHTML']) and $_POST['stripHTML']=='true'){$message_body = strip_tags($message_body);$message_type='text';} 


try { 
    include "libmail.php"; 

    foreach ($owner_email as $owner_email_item) { 
     $m= new Mail("utf-8"); 
     $m->From($user_email); 
     $m->To($owner_email_item); 
     $m->Subject($subject); 
     $m->Body($message_body,$message_type); 
     //$m->log_on(true); 

     if(isset($_FILES['attachment'])){ 
      if($_FILES['attachment']['size']>$max_file_size){ 
       $error_text=$error_text_filesize . ' ' . $max_file_size . 'bytes'; 
       die($error_text);   
      }else{   
       if(preg_match($file_types,$_FILES['attachment']['name'])){ 
        $m->Attach($_FILES['attachment']['tmp_name'],$_FILES['attachment']['name'],'','attachment'); 
       }else{ 
        $error_text=$error_text_filetype; 
        die($error_text);    
       } 
      }  
     } 
     if(!$use_smtp){ 
      $m->smtp_on($host, $username, $password, $port); 
     } 

     $m->Send(); 
    } 

    die('success'); 

}catch(Exception $mail){ 
    die($mail); 
} 
?> 
+0

[foreach 문에 대한 공급 잘못된 인수() (의 사용 가능한 복제 http://stackoverflow.com/questions/2630013/invalid-argument-supplied-for-foreach에 $owner_email='[email protected]'; 변경) – thewaywewere

답변

0

foreach 하지만 당신은 문자열을 전달하고 있습니다. 자세한 내용은 PHP Docs을 참조하십시오. 두 번째 줄에

, $owner_email=array('[email protected]');

+0

작동 중입니다. 고마워요. –

+0

정답으로 받아 들여도 무방합니다 (투표 아래의 체크 표시를 클릭하십시오)! – MasterOdin

관련 문제