PHP重新提交和订阅数据问题

I'm facing two issue with the following code.

  1. I'm using the following code to submit the subscriber's email address to my email address the code is working and email is also being sent but the issue is that I can't see subscriber's email address.
  2. Every time when I refresh the page it shows an alert box saying resubmission confirmation and when I properly refresh the page by closing the alert box or pressing ok then it shows the success message that was showing while the subscriber submit his/her email.

The code is below :

     <?php

                if(isset($_POST['submit'])){
                  $email=$_POST['email'];

                  //send mail 
                 $to='info@soapbox.media';
                 $subject='New Subscriber';
                 $body='<html>
                 <body>
                 <h3>Feedback</h3>
                 <hr>

                 <p> Email :<br/>'.$email.'</p>

                 </body>

                 </html>';

                 $headers  ="From:<".$email.">
";
                 $headers .="reply-To:".$email."
";
                 $headers .="NINE-Version: 1.0
";
                 $headers .="Content-type: text/html; charset=utf-8";

              //confirmation mail
                         $user=$email;
                         $usersubject = "SoapBox";
                         $userheaders = "From:  info@soapbox.media
";
                         $usermessage = "Thank you for subscribing SoapBox.";


                        //sending process
                         $send=mail($to, $subject, $body, $headers);
                         $confirm=mail($user, $usersubject, $userheaders,$usermessage );

                         if($send && $confirm){
                          echo "<div class='alert alert-success alert-dismissible fade show'>
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                            <strong>Success!</strong> You have subscribed successfully.
                          </div>";    
                         }

                         else{
                          echo "Failed";
                         }

                        }




?>               
duanlou7910
duanlou7910 请问有人可以回答这个问题吗?
一年多之前 回复
dqunzip3183
dqunzip3183 但这不是解决方案。我试过了,我想要提到的那个令人耳目一新的问题也要解决了。
一年多之前 回复
dqiz20794
dqiz20794 $confirm=mail($user,$usersubject,$usermessage,$userheaders);
一年多之前 回复
douji9518
douji9518 请给我解决方案。
一年多之前 回复
duansha8115
duansha8115 对不起,但没有得到你。你想说什么?
一年多之前 回复
duanpo7282
duanpo7282 哦;这是一个错字问题。你在第二个mail()函数中混合了标题的参数。
一年多之前 回复
dszn2485
dszn2485 后续代码var_dump($_POST['邮件']);有什么价值?
一年多之前 回复

1个回答

  1. $confirm=mail($user, $usersubject, $usermessage, $userheaders); by @Funk Forty Niner

  2. place a header('location: ' . $_SERVER['PHP_SELF']); after you've sent the mail - you will get rid of the post-header, so no more popup after F5 - You will get rid of your confirmation msg aswell so you could add a GET parameter to your URL to show the confirmation message.

展开翻译

译文




  1. $ confirm = mail($ user,$ usersubject,$ usermessage,$ userheaders) ; </ code> by @Funk Forty Niner </ p> </ li>

  2. 放置标题('location:'。$ _SERVER ['PHP_SELF']); </ code >在您发送邮件之后 - 您将摆脱后标题,因此在F5之后不再弹出 - 您将摆脱您的确认消息以及您可以添加 GET </ code>参数到 您的网址以显示确认消息。</ p> </ li>
    </ ol>
    </ div>

dove2199
dove2199 我给了你工具和一些提示 - 现在开始编码:)
一年多之前 回复
douxun4860
douxun4860 我的意思是我上面写的代码
一年多之前 回复
douxi4114
douxi4114 我应该保留剩余的代码吗?
一年多之前 回复
dongzexi5125
dongzexi5125 example.php是您正在编写此代码的文件。将其替换为您用于访问此文件的uri - 查看您的浏览器地址栏;)
一年多之前 回复
dongqi8114
dongqi8114 我没有收到你,因为我没有像你指定example.php那样使用任何外部文件。 请更改我上面提供的代码,以便我可以实现
一年多之前 回复
dongshen6060
dongshen6060 header('location:example.php?success'); 在你的脚本if(isset($ _ GET ['success''])){echo'...'; }
一年多之前 回复
dongque8332
dongque8332 如果你能尽快帮助我
一年多之前 回复
dongyang2229
dongyang2229 我尝试了第一个答案,它没有工作,如果我实施第二个,那么我将如何显示成功消息?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问