No warning after sending the message

Asked

Viewed 69 times

1

I need a hint: I have a problem with the PHP code displaying a warning after sending a message. The message is sent without problems, but no warning is displayed. Neither for success nor for error. Follow the PHP code:

<?php

    if (!$mail->Send()) {

        echo "<script type='text/javascript'>window.alert('".$nome."! Sua mensagem foi enviada com sucesso!');</script>";
        echo '<meta HTTP-EQUIV="Refresh" CONTENT="1; URL=index.php">';


    } else {
        echo "<script>alert('Houve um erro! \nFavor tente mais tarde.');</script>";
        exit;
    }
?>
  • gives a tidy in the Code!

  • Thanks, Aderbal. Yes I organized the code, I found myself and I got it solved! Abs

1 answer

1


What you want to do is something relatively simple, but it is necessary to know how you are doing this task, if you have some scheme like mvc or if you are doing it in a procedural way, if you are doing it in the same file or if you are directing the action to another file. But I will try to assume that you are using a procedural method and that you are performing the task in the same file. First of all I recommend to work your Alerts as bootstrap and when you are more experienced use Alertsweet and leave this information displayed more professionally and stylized.

Okay, let’s go to the code. Use only the statement in a javascript scope and you can do the whole task as follows.

echo "<script> alert('".$nome."! Sua mensagem foi enviada com sucesso!');
window.reload(); </script>"

If you want to be directed to another page using javascript after Alert display, replace window.reload() for window.location.href, Exp: redirect to google page window.location.href= "https://google.com";, if you do not use the http or https indexing identifier, the code will interpret that the string is part of your project and will try to search for it as a suffix or file, this may be useful if you are validating your email sending in another file. I recommend that you see to start your studies the Phpmailer for sending emails, the sending of native php is very inefficient in production environment has no investment of people committed to its improvement long. I hope I helped. Hugs!

  • 1

    Ôpa, Junior Silva. Thank you very much for the tips, helped me very much to resolution and reflection! Abs

  • You’re welcome, I’m happy to help you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.