如果条件不能在PHP脚本中工作

时间:2018-03-06 15:09:01

标签: php

我正在尝试仅在我点击按钮并发送电子邮件时才显示消息,但在我点击按钮之前消息已经存在。

我使用提交按钮调用PHP脚本,该按钮在同一页面上有一个操作表单,这是我调用的PHP脚本:

DatabaseReference mDatabaseRefff = FirebaseDatabase.getInstance().getReference(Uid).child(selectedId).child(selectedId).child(key);


    dbEvent = mDatabaseRefff.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {


            Toast.makeText(ImagesActivity.this, "Item deleted ", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });


}

fisrt echo总是被显示,它尝试添加另一个if:

 if(isset($_POST['envEmail']))
                    {
                      $nome=  $_POST['name'];
                      $emailcliente=  $_POST['emailCliente'];
                      $assunto=  $_POST['assunto'];
                      $menssagem=  $_POST['message'];
                          $to  = 'jun@paconstrushop.com.br'; //can receive notification

                          $subject = $assunto;
                          $message = 'Email enviado por:'.$nome."\n".$menssagem;
                          $headers = 'From:'.$emailcliente. "\r\n" .
                              'Reply-To: jun@paconstrushop.com.br' . "\r\n" .
                              'X-Mailer: PHP/' . phpversion();

                          mail($to, $subject, $message, $headers);

                          echo " <div id=success_message style=width:100%; height:100%;  > <h3>Sent your message successfully!</h3> </div>";
                    }else {
                        echo "<div id=error_message style=width:100%; height:100%;  > <h3>Error</h3> Sorry there was an error sending your form. </div>";
                    }

                     ?>

但它没有改变,如果电子邮件成功,有人可以告诉我如何显示吗?

这是调用php脚本的div和表单:

 if( mail($to, $subject, $message, $headers)){
   echo"success";
  }else{
   echo"error";
   }

2 个答案:

答案 0 :(得分:1)

问题在于提交表单的按钮,而不是按钮标签,我应该使用类型为submit的输入标签,当我进行这些更改时,它会起作用。

答案 1 :(得分:0)

你试过这个:

  if(isset($_POST['envEmail']))
  {
    $nome=  $_POST['name'];
    $emailcliente=  $_POST['emailCliente'];
    $assunto=  $_POST['assunto'];
    $menssagem=  $_POST['message'];
    $to  = 'jun@paconstrushop.com.br'; //can receive notification

    $subject = $assunto;
    $message = 'Email enviado por:'.$nome."\n".$menssagem;
    $headers = 'From:'.$emailcliente. "\r\n" .
        'Reply-To: jun@paconstrushop.com.br' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    if(@mail($to, $subject, $message, $headers))
    {
        echo " <div id=success_message style=width:100%; height:100%;  > <h3>Sent your message successfully!</h3> </div>";
    }
    else 
    {
      echo "<div id=error_message style=width:100%; height:100%;  > <h3>Error</h3> Sorry there was an error sending your form. </div>";
    }
  }