2016-09-08 2 views
0

상태를 업데이트하면 이메일이 전송됩니다. 문제는 많은 다른 필드가 있으며 그 중 누군가를 업데이트 할 때마다 이메일을 다시 촬영한다는 것입니다. 이메일이나 팩스로 보내려는 경우 확인을 요청하고 싶습니다. 콘솔에서 AJAX를 사용하여 이메일을 보냈지 만받은 편지함에는 아무것도 표시되지 않습니다. 항상이 거짓이 될 것입니다자바 스크립트 확인시 PHP 코드 실행

자바 스크립트 코드

<script type="text/javascript"> 
function send_email(){ 

    var delete_confirmed=confirm("Are you sure you want to send email?"); 

    if (delete_confirmed==true) { 

    $.ajax({ 
     type: "POST", 
     url: 'email.php', 
     data:{action:'call_this'}, 
     success:function() { 
     console.log('email sent'); 
     } 
    }); 
}} 
</script> 

email.php로

if(isset($_POST['status']) == 'completed' && $_POST['action'] == 'call_this'){ 

     $cmail = new PHPMailer; 

     $cmail->isSMTP();       // Set mailer to use SMTP 
     $cmail->SMTPAuth = true;      // Enable SMTP authentication 

     $cmail->Host = $smtp_server;   // Specify main and backup SMTP servers 
     $cmail->Username = $username;    // SMTP username 
     $cmail->Password = $password;    // SMTP password 
     $cmail->SMTPSecure = "ssl";     // Enable TLS encryption, `ssl` also accepted 
     $cmail->Port = 465;       // TCP port to connect to 

     $cmail->setFrom("[email protected]", "Example"); 
     $q_mail = "SELECT * FROM order_details WHERE order_id = '$_GET[edit_id]'"; 

     $r_mail = mysqli_query($conn, $q_mail); 
     while ($r_rows = mysqli_fetch_assoc($r_mail)) { 

     $cmail->addAddress($r_rows['email'], $r_rows['firstname']); // Add a recipient 
     $cmail->isHTML(true); // Set email format to HTML 

     $bodyContent = 'test message'; 

     $cmail->Subject = "test subject" ; 
     $cmail->Body = $bodyContent; 

     if(!$cmail->send()) { 
      $error = $cmail->ErrorInfo; 
     } else { 
      $error = 'Message has been sent'; 
       } 

      } 

     } 

형태의 HTML 당신의 PHP에서

<div class="col-md-2" style="padding-left:0px;" ></br> 
    <input type="submit" class="btn navbar-bar btn-xs btn-success" name="status" onclick="send_email();" value="Update"> 
</div> 
+1

html도 표시 –

+0

CLARIFICATION PLEASE : 상태가 변경된 경우 전자 메일을 보내지 않으시겠습니까? 옳고 그름? – RiggsFolly

+0

'$ _POST [ 'status']'는 어디에서 보내나요? –

답변

2

당신이 isset($_POST['status']) == 'completed'를 확인하고 있습니다. isset은 부울 만 반환합니다. 또한 상태를 email.php으로 전달하지 않을 때 항상 액션 만 false로 설정됩니다. 이 문제를 해결하려면 몇 가지 변경해야합니다. 첫 번째는 자바 스크립트입니다.

$.ajax({ 
    type: "POST", 
    url: 'email.php', 
    data:{action:'call_this', status: 'completed'}, 
    success:function() { 
     console.log('email sent'); 
    } 

});

두 번째는 PHP 스크립트입니다 :

if((isset($_POST['status']) && $_POST['status'] == 'completed') && $_POST['action'] == 'call_this'){ 
+0

나는 이메일을 보낼 때 세 가지 상태가 더있다. 현재, 당신이 말했던 변화를 만들었고 그것이 작동하지 않는다. :( –

0

당신은 아약스 요청에서 어떤 종류의 피드백 (feedback)을 받고 있다는 사실은 문제가 다른 곳에서 거짓말을 제안합니다. 아래 라인은 올바르지 않습니다 - edit_id에서 따옴표가 누락되었습니다. 그리고 문자열 내에서 $_GET/$_POST 변수에 액세스 할 때 나는 항상 아래와 같이 중괄호로 둘러 쌉니다.

질문을 올렸을 때 잘못 입력되었지만 예상대로 일이 발생하지 않을 때마다 오류 로그를 확인할 수 있습니다.

you look at this thread의 경우 try/catch을 사용하면 문제가있는 곳을 추측 할 수 있습니다.

관련 문제