2013-11-09 3 views
-2

양식 데이터를 보내는 데 사용하는 기본 연락처 PHP 스크립트에 문제가 있습니다. 문제의 페이지 : http://www.edenapartments.co.uk/bookings.htmlPHP mail() 함수와 관련된 문제

내 PHP는 제한되어 있지만, 문제가 될 수있는 구문에 대해 명확한 사실을 발견 할 수 없습니다. 스크립트는 몇 가지 기본적인 오류 검사를 수행하고 질문에 varible의 $ 오류

if($email && !ValidateEmail($email)) 
{ 
$error .= 'Invalid E-mail !!! 
'; 
} 

의 결과 다음 PHP를 저장합니다

if(!$error) 
{ 
$mail = mail(WEBMASTER_EMAIL, $subject, $message, 
    "From: ".$name." <".$email."> \r\n" 
    ."Subject: BOOKING FORM SUBMISSION \r\n" 
    ."X-Mailer: PHP/".phpversion()); 
if($mail) 
    { 
    echo 'OK'; 
    } 
    else { 
    echo 'Mail called, no mail'; 
    } 
} 
else 
    { 
    echo '<div class="notification_error">'.$error.'</div>'; 
    } 

}

하면 I 입력 밥 @의 HJ로 전자 메일, PHP 스크립트는이 오류를 인식하고 스크립트에서 응답을 반환합니다. "잘못된 전자 메일"이므로 양식 데이터가 스크립트에 보내져 검사관의 페이지를보고 데이터가 올바르게 구문 분석되고 있음을 확인할 수 있습니다. .

오류가없는 경우 응답은 "Mail called, mail was sending"이므로 mail() 함수에 문제가 있다고 가정합니다.

머리글을 필드에서 똑같은 결과로 단순화하려고했습니다.

어떤 아이디어? 위대한 커뮤니티에 미리 감사드립니다.

은 내가 스크립트를 호출하는 데 사용하는 JQuery와 포함 가치가있을 수도 있습니다 생각하지만, PHP의 반응 부여 "라는 메일, 메일 변 불가"나는 .. 문제의 원인은하지 jQuery를 추정

jQuery("#booking-form").submit(function(){ 
      _CONTACT = jQuery(this); 
      var str = _CONTACT.serialize(); 
      jQuery.ajax({ 
        type: "POST", 
        url: "basic_booking_form/booking.php", 
        data: str, 
        success: function(msg){ 
         jQuery(document).ajaxComplete(function(event, request, settings){ 
          if(msg == 'OK') { 
           result = '<div class="notification_ok">Your message has been sent Succesfully. Thank you.</div>'; 
           jQuery("#fields").hide(); 
           _CONTACT.hide(); 
           _CONTACT.html(result).slideDown("slow"); 
           _CONTACT.html(result); 
          } 
          else { 
           result = msg; 
           _CONTACT.find('#note').html(result).slideDown("slow"); 
          } 


         }); 
        } 

       }); 
      return false; 
      }); 
+0

한 정도로 정보가 없습니다. 'display_errors = 1'과'error_reporting = E_ALL'로 모든 오류를 페이지에 표시 할 수 있습니까 – Spell

+2

오류보고를 사용하고 페이지를 요청합니다 (아약스없이). 발견 된 오류를보고하십시오. 또한 귀하의 스크립트는 폭력적으로 공개되어 있습니다. '$ name'과'$ email' 입력을 살균하지 않고, 누군가가 임의의 헤더를이 이메일에 주입하도록 허용하고 있습니다. –

+1

Off Topic : 이메일이 유효한지 확인하려면'filter_var'를 사용해야합니다. http://php.net/manual/en/function.filter-var.php –

답변

-2

업데이트 "SwiftMail"을 사용하여 훨씬 더 나은 솔루션을 얻게 된 것을 기쁘게 생각합니다. 이러한 일반적인 PHP 문의 양식 자습서를 익히고 자하는 분들을 위해 사용하는 것이 좋습니다. 구현이 간단했고 이제는 PHP 메일() 기능보다는 내 메일 서버 smtp 설정을 사용하여 메일을 보내고 있습니다.

결과의 PHP 코드 (내 파일 구조에 swiftmail를 포함 후) :

<?php 

require_once '../swift_mail/lib/swift_required.php'; 

include 'config.php'; 
    error_reporting (E_ALL^E_NOTICE); 
    $post = (!empty($_POST)) ? true : false; 

if($post) 
    { 
include 'functions.php'; 
$name = stripslashes($_POST['name']); 
$apartment = trim($_POST['apartment']); 
$email = trim($_POST['email']); 
$tel = trim($_POST['tel']); 
$mob = trim($_POST['mob']); 
$arrive = trim($_POST['arrive']); 
$depart = trim($_POST['depart']); 
$guests = trim($_POST['guests']); 
$guests13 = trim($_POST['guests13']); 
$accept = trim($_POST['accept']); 

$message = "Name: ".$name."\n"."Tel: ".$tel."\n"."Mobile: ".$mob."\n"."Apartment: ".$apartment."\n"."Arrive: ".$arrive."\n"."Depart: ".$depart."\n"."Guests: ".$guests."\n"."Guests under 13: ".$guests13."\n".stripslashes($_POST['message'])."\n"."Terms Accepted: ".$accept; 

$error = ''; 

// Create the Transport 
$transport = Swift_SmtpTransport::newInstance('mail.******.co.uk', 26) 
    ->setUsername('******') 
    ->setPassword('******') 
; 
if(!$transport) { 
$error .= 'error creating transport'; 
} 

// Create the Mailer using your created Transport 
$mailer = Swift_Mailer::newInstance($transport); 

// Check name 
if(!$name) 
    { 
    $error .= 'You need to enter a name'; 
    } 
// Check email 
if(!$email) 
    { 
    $error .= 'Please enter a valid e-mail. It will not be stored or added to any mailing list.'; 
    } 
if($email && !ValidateEmail($email)) 
    { 
    $error .= 'Invalid E-mail !!!'; 
    } 
if(!$accept) 
    { 
    $error .= 'You must accept the terms and conditions to make a reservation.'; 
    } 
if(!$error) 
    { 
$mail_to_send = Swift_Message::newInstance() 
    // Give the message a subject 
    ->setSubject('Booking Form Submission') 
    // Set the From address with an associative array 
    ->setFrom(array($email => $name)) 
    ->setReplyTo($email) 
    // Set the To addresses with an associative array 
    ->setTo(WEBMASTER_EMAIL) 
    // Give it a body 
    ->setBody($message) 
    ; 
// Send the message 
$result = $mailer->send($mail_to_send); 
    if($result) { 
     echo 'OK'; 
    } 
    else { 
     echo 'mailer not successful'; 
    } 
} 
else 
    { 
    echo '<pre> 
<div class="notification_error">'.$error.'</div> 
</pre>'; 
    } 

} >