2016-01-21 81 views
0

打印php如果条件真或假导致我的html与ajax或任何其他解决方案的联系表单,我想打印。如果条件导致.html与ajax

if($response.success==false) { 
     echo '<h2>Your message was not sent. Captcha fail</h2>';} 

     else 
     { 
      $mail = mail(Hanse, $subject, $message, 
      "From: ".$name." <".$email.">\r\n" 
      ."Reply-To: ".$email."\r\n" 
      ."X-Mailer: PHP/" . phpversion()); 


      if($mail) 
       { 
        echo 'Your message was sent'; 
       } 

     } 


} 

但是这段代码并没有和我的html文件一起使用。我有contact.html和mail.php文件。我想在mail.php中显示contact.html页面的结果。在这个php代码中,我只能用echo打印结果。但我想在我的html页面显示这个结果。

+2

请在谷歌搜索AJAX。并执行它。这些是非常基本的东西,我们不能在这里教这些。 – Pupil

回答

1

重新指定或使用ajax调用。

变化的index.html的index.php

在mail.php,补充一点:

if($mail){ 
    $message= 'Your message was sent'; 
    header("location:index.php?message=".$message); 
} 

添加检查中的index.php

if(isset($_GET['message'])){ 
    echo $_GET['message']; 
} 
+0

我需要你的帮助:/ – Ayaz

+0

@Ayaz action =“contact.php”你的动作是contact.php,你的代码在mail.php中。请在继续阅读之前先查看教程。 –