简体   繁体   中英

PHP re-submission and subscription data issue

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.">\r\n";
                 $headers .="reply-To:".$email."\r\n";
                 $headers .="NINE-Version: 1.0\r\n";
                 $headers .="Content-type: text/html; charset=utf-8";

              //confirmation mail
                         $user=$email;
                         $usersubject = "SoapBox";
                         $userheaders = "From:  info@soapbox.media\n";
                         $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";
                         }

                        }




?>               
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM