donglao6169 2015-12-11 22:29
浏览 270
已采纳

如何在表单提交的html页面中显示PHP的成功消息

I am developing website in html. In Careers.html page i am having Apply button. On clicking that apply button it will send the mail using php file. On suceess event i need to set the alert or to show the div on the same Careers.html page.

Careers.html

<form method="post" action="Applyresume.php" enctype="multipart/form-data"> 
     <tr>
     <td>First Name  </td>
     <td><input type="TextBox" name="First_Name" class="applytext" required></td>
     </tr>
     <tr>
     <td>Last Name </td>
     <td><input type="TextBox" name="Last_Name" class="applytext" required></td>
     </tr>
     <tr>
     <td>E-mail  </td>
     <td><input type="TextBox" name="email" class="applytext" required></td>
     </tr>
     <tr>
     <td>Phone  </td>
     <td><input type="TextBox" name="Phone_No" class="applytext" required></td>
     </tr>
      <tr>
    <td>Attachment  </td>
    <td><input type="file" name="attachment" maxlength="50" allow="text/*" class="applytext" required></td>
    </tr>
     <tr>
     <td colspan="2"><input type="submit" name="button" class="send-resume" value="SEND" style="margin-left:24%;">
    <input type="reset" value="RESET" style="margin-left:8%"></td>
     </tr>
     </form>

Applyresume.php

 <?php 
    if($_POST && isset($_FILES['attachment']))
    {  
        $name= $_POST['First_Name'];
        $lname= $_POST['Last_Name'];
        $email= $_POST['email'];
        $phonenum = $_POST['Phone_No'];
        $from_email = $_POST['email']; //sender email
        $recipient_email = 'nisha@acute.company'; //recipient email
        $subject = 'Test Email '; //subject of email
        $message = 'Resume attached below.'; //message body
            $emailbod = "$name
        $lname
         $email
         $phonenum";
        //get file details we need
        $file_tmp_name    = $_FILES['attachment']['tmp_name'];
        $file_name        = $_FILES['attachment']['name'];
        $file_size        = $_FILES['attachment']['size'];
        $file_type        = $_FILES['attachment']['type'];
        $file_error       = $_FILES['attachment']['error'];

        $user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);

        if($file_error>0)
        {
            die('upload error');
        }
        //read from the uploaded file & base64_encode content for the mail
        $handle = fopen($file_tmp_name, "r");
        $content = fread($handle, $file_size);
        fclose($handle);
        $encoded_content = chunk_split(base64_encode($content));


            $boundary = md5("sanwebe"); 
            //header
            $headers = "MIME-Version: 1.0
"; 
            $headers .= "From:".$from_email."
"; 
            $headers .= "Reply-To: ".$user_email."" . "
";
            $headers .= "Content-Type: multipart/mixed; boundary = $boundary

"; 

            //plain text 
            $body = "--$boundary
";
            $body .= "Content-Type: text/plain; charset=ISO-8859-1
";
            $body .= "Content-Transfer-Encoding: base64

"; 
            $body .= chunk_split(base64_encode($emailbod)); 

            //attachment
            $body .= "--$boundary
";
            $body .="Content-Type: $file_type; name=\"$file_name\"
";
            $body .="Content-Disposition: attachment; filename=\"$file_name\"
";
            $body .="Content-Transfer-Encoding: base64
";
            $body .="X-Attachment-Id: ".rand(1000,99999)."

"; 
            $body .= $encoded_content; 



        $sentMail = @mail($recipient_email, $subject,  $body, $headers);
        if($sentMail) //output success or failure messages
        { 
                 echo '<script type="text/javascript">alert("Thanks for your interest. Your Resume has been sent to HR@prominData.com");window.location.assign("Careers.html");</script>';
        }else
       {
             echo"<script>alert('Could not send mail! Please check your PHP mail configuration.')</script>";
        }

    }
    ?>

My problem is I need to set the success alert in the same html page. But here my success alert is opening in PHP page.

How to add this php code in same html page?

展开全部

  • 写回答

2条回答 默认 最新

  • dongwo5686 2015-12-11 22:35
    关注

    To view the message or alert on the same page, you can just copy your php code in the same HTML page. Do it as below

    your_html.php

    <form method="post" action="" enctype="multipart/form-data"> 
         <tr>
         <td>First Name  </td>
         <td><input type="TextBox" name="First_Name" class="applytext" required></td>
         </tr>
         <tr>
         <td>Last Name </td>
         <td><input type="TextBox" name="Last_Name" class="applytext" required></td>
         </tr>
         <tr>
         <td>E-mail  </td>
         <td><input type="TextBox" name="email" class="applytext" required></td>
         </tr>
         <tr>
         <td>Phone  </td>
         <td><input type="TextBox" name="Phone_No" class="applytext" required></td>
         </tr>
          <tr>
        <td>Attachment  </td>
        <td><input type="file" name="attachment" maxlength="50" allow="text/*" class="applytext" required></td>
        </tr>
         <tr>
         <td colspan="2"><input type="submit" name="button" class="send-resume" value="SEND" style="margin-left:24%;">
        <input type="reset" value="RESET" style="margin-left:8%"></td>
         </tr>
         </form>
    
    
    <?php 
        if($_POST && isset($_FILES['attachment']))
        {  
            $name= $_POST['First_Name'];
            $lname= $_POST['Last_Name'];
            $email= $_POST['email'];
            $phonenum = $_POST['Phone_No'];
            $from_email = $_POST['email']; //sender email
            $recipient_email = 'nisha@acute.company'; //recipient email
            $subject = 'Test Email '; //subject of email
            $message = 'Resume attached below.'; //message body
                $emailbod = "$name
            $lname
             $email
             $phonenum";
            //get file details we need
            $file_tmp_name    = $_FILES['attachment']['tmp_name'];
            $file_name        = $_FILES['attachment']['name'];
            $file_size        = $_FILES['attachment']['size'];
            $file_type        = $_FILES['attachment']['type'];
            $file_error       = $_FILES['attachment']['error'];
    
            $user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
    
            if($file_error>0)
            {
                die('upload error');
            }
            //read from the uploaded file & base64_encode content for the mail
            $handle = fopen($file_tmp_name, "r");
            $content = fread($handle, $file_size);
            fclose($handle);
            $encoded_content = chunk_split(base64_encode($content));
    
    
                $boundary = md5("sanwebe"); 
                //header
                $headers = "MIME-Version: 1.0
    "; 
                $headers .= "From:".$from_email."
    "; 
                $headers .= "Reply-To: ".$user_email."" . "
    ";
                $headers .= "Content-Type: multipart/mixed; boundary = $boundary
    
    "; 
    
                //plain text 
                $body = "--$boundary
    ";
                $body .= "Content-Type: text/plain; charset=ISO-8859-1
    ";
                $body .= "Content-Transfer-Encoding: base64
    
    "; 
                $body .= chunk_split(base64_encode($emailbod)); 
    
                //attachment
                $body .= "--$boundary
    ";
                $body .="Content-Type: $file_type; name=\"$file_name\"
    ";
                $body .="Content-Disposition: attachment; filename=\"$file_name\"
    ";
                $body .="Content-Transfer-Encoding: base64
    ";
                $body .="X-Attachment-Id: ".rand(1000,99999)."
    
    "; 
                $body .= $encoded_content; 
    
    
    
            $sentMail = @mail($recipient_email, $subject,  $body, $headers);
            if($sentMail) //output success or failure messages
            { 
                     echo '<script type="text/javascript">alert("Thanks for your interest. Your Resume has been sent to HR@prominData.com");window.location.assign("Careers.html");</script>';
            }else
           {
                 echo"<script>alert('Could not send mail! Please check your PHP mail configuration.')</script>";
            }
    
        }
        ?>
    

    Dont forget to remove the action attribute of <form>. Also the extension of your HTML page should be changed to php.

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 mes系统扫码追溯功能
  • ¥40 selenium访问信用中国
  • ¥15 电视大赛投票系统的c语言代码怎么做
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部