0

ADJOURNMENT

I'm sorry for delay in the response but another project had priority. I followed the dimitry advice and added the ajax call. Front-end validation with validated jquery and jquery form for sending ajax.

I state that the management of the pages of the site is entrusted to a php switch.

If the form is ok it should go to thanks.php with simple custom message (hello NAME, .... MAIL) and call form-validation.php which executes phpMailer. I can go to thanks.php with window.location.href but the data does not pass to the php page and I don't know how to call two different pages.

HTML CODE (Essential)

<form method="post" action="thanks" id="form_contatti" class="contact100-form" autocomplete="on">
    <div class="form-group col-lg-12">
        <input type="text" name="name" class="form-control" placeholder="Name*" autofocus value=""  required>
    </div>
    <div class="form-group col-lg-12">
        <input type="text" name="surname" class="form-control" placeholder="S*" autofocus valueurname=""  required>
    </div>
    <div id="Pulsante" class="text-center">
        <!-- Generated With Jquery on page ready -->
    </div>
</form>

Validation Code

submitHandler: function(form) {            
        $.ajax({
            url:  'form_validation.php',
            type: $(form).attr('method'),
            data: $(form).serialize(),
            cache: false,//On dev disable cache. Remove on production
            success: function(response) {
                        alert("Thank you for your comment!");
                        window.location.href = $(form).attr('action');
                    }            
        });
    }

I tried to make the call synchronous, to insert both calls in get and then in post, to insert the second ajax in the first but nothing.



I'm use phpmailer to send data from the form, unfortunately I also have to send two files (cv and cover letter) and this slows it down a lot (it takes more than 5 seconds to load the page).

Aruba Server,
HTTPS,
NO DATABASE
Windows Hosting,
Php 7.2 available

Uses an auto@domainname.ext to have the email sent from the address entered in the form.

I have no direct access (neither to the server nor to the aruba administration panel), therefore I cannot install / modify / configure / enable anything.

Is there a way to make sending asynchronous or something?
I have looked at other answers here but they are not for me because they plan to install libraries or change settings.

If needed I can attach a server's info.php screen.
I have little php experience and I don't know object-oriented programming so it's all more difficult.

Thank you very much.

Max
  • 37
  • 5
  • 1
    You can try post data form via javascript. – Dmitry Leiko Dec 06 '19 at 10:00
  • 1
    PHP is not asynchronous. As suggested by Dmitry you can execute the request using an AJAX call. If you prefer a PHP solution, then you can call your PHP script but terminate early using the example in this link. https://stackoverflow.com/questions/15273570/continue-processing-php-after-sending-http-response . In summary, by terminating early you can continue processing your php code after a response has been sent to the client. But note, you will not get any confirmation that your process is complete. – Syed Hussim Dec 06 '19 at 11:17

1 Answers1

0

SMTP to remote servers is simply not well suited to processing during page submission. The best way to deal with it is to use a local mail server and submit to that, which will be very fast - it's quite likely that you already have one. Try setting it like this, see if it works:

$mail->isSMTP();
$mail->Port = 25;
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = false;
Synchro
  • 35,538
  • 15
  • 81
  • 104
  • Sorry but this don't work. Return this error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting. Obviously I read the page in question but, unfortunately, I didn't get anything out of it – Max Dec 06 '19 at 11:07
  • OK so it sounds like you don't have a local mail server - does your ISP provide one? Have you read their docs on how to send email from their servers? Otherwise I'd suggest storing messages in a queue and doing the actual sending in a separate process (e.g. a cron job), though you may have trouble setting that up if your hosting provider limits what you can do. It might be worth switching providers to one that doesn't limit you so much. – Synchro Dec 06 '19 at 11:11
  • Thanks Syncro, in the end I chose Ajax, it seemed to me the simplest and most effective solution. Unfortunately the server is not mine and I cannot change supplier. – Max Dec 20 '19 at 10:51