Pop-up on successful mail delivery

Asked 2 years ago, Updated 2 years ago, 32 views

<?php
header("Location:http://www.studiojpg.co.kr");

// Syntax to check for empty fields
if(empty($_POST['name']) || // Verify that the name value passed to post is empty
   empty($_POST['email']) || // Verify email value is empty
   empty ($_POST['phone']) || // Verify phone value is empty
   empty ($_POST['message']) || // Verify message value is empty
   !filter_var ($_POST['email'],FILTER_VALIDATE_EMAIL)) // Verify that the forwarded email value is a valid email value
   {
    echo "Please confirm the acquisition!";
    return false;
   }
// Secure coding to prevent Cross-Site Scripting (XSS)
// Strip_tags() -> Remove html and php tags from string
// htmlspecialchars() -> Convert special characters to HTML entities
// To prepare for malicious insertion of special characters

$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));

$to = '[email protected]'; // Part of the recipient's email address
$email_subject = "FROM: $name"; // Part of the mail title
$email_body = "This is an email from the homepage form mail.\n\n."Details include:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "Reply-To: $email_address\r"; // Reply Address

mail($to,'=?UTF-8?B?'.base64_encode($email_subject).'?=',$email_body,$headers);
return true;    



?>

Here's the sauce.

If you send an e-mail here, 'It was sent successfully.'

I want to make this message pop. What should I do?

popup php

2022-09-21 21:35

1 Answers

When you say "make a message pop up," you mean you're going to put up a pop-up warning, right? This is a really old problem, and if you search a little bit, you'll see tens of millions of examples, so I'll just show you a rough outline here.

(This code has not been tested. Try it.)

20th century method: Write this instead of return true; at the end.

header('Content-Type: text/html; charset=UTF-8');
echo "<script>alert ('sent successfully'); window.location.href='http://www.studiojpg.co.kr'</script>";"

21st Century Method: Adjust the JS of the HTML form to call this PHP script ajax.(Assume that the PHP source returns a string to echo 'success'; upon successful mail delivery)

<script>
var form = document.getElementById('send_mail');
form.addEventlistener('submit', function (e) {
    e.preventDefault();
    var xmlhttp = new XMLHttpRequest();
    var emailData = new FormData(e.target);
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            if (this.responseText == 'success') {
                alert('Sent successfully.');
                window.location.href = 'http://www.studiojpg.co.kr';
            } } else {
                alert('Sent unsuccessfully. Please do it again.');
                return false;
            }
        } } else {
            alert('Server Error!! '+this.status);
        }
    };
    xmlhttp.open("POST", "sendmail.php");
    xmlhttp.send(emailData);
});
</script>


2022-09-21 21:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.