D
D
Dmitry2015-08-26 22:09:25
PHP
Dmitry, 2015-08-26 22:09:25

How can I make sure that nothing happens on the screen after sending an email?

Good day.
Please tell me how to configure Phpmailer so that after clicking the "Send" button, nothing else happens except for sending the letter (it doesn't redirect me to other pages, no windows pop up, etc.).
At the moment, my settings_mail.php file says

if ($mail->send()){
    header("Location: https://www.google.com/"); 
}

and redirects me to the main page of Google, if this line is removed, then after sending I have a white page.
UPD. In this video, a solution to the problem using AJAX https://youtu.be/FQWO03fgUPM?t=16m45s
Watch from 16:45.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Pavlenko, 2015-08-26
@Odinokun

You need to hook the form's submit event and send an AJAX request when the form is clicked.
If you are using a framework, google "<framework name> AJAX Forms".
In any case, you need a basic understanding of JS (or in particular JQuery), then you can easily implement everything.

A
Andrew, 2015-08-27
@ntzch

There are two options, it seems to me:
1) As already mentioned - use AJAX (the best option)
2) header('Location: '.$_SERVER['REQUEST_URI']);- paste instead of redirecting to Google, so the page will simply reload

I
Ildar Saribzhanov, 2015-08-26
@Bluz

I suspect that you have a condition for displaying the form, like this

if ($mail->send()){
    header("Location: https://www.google.com/"); 
} else {
    // show html form
}

You need to remove this condition so that the form is always displayed, or display a message about successful submission instead of a redirect. Or combine these solutions)
if ($mail->send()){
   echo 'Thank! Your message has been sent!';
}

// show html form

Well, in general, I would like to see a little more code in order to understand what the problem is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question