I have a contact form, and all the php works just fine with emails being sent successfully, but the issue is that an email is sent as soon as the page is loaded/refreshed. I want the code to execute only when a form (with multiple inputs) has been filled in and the submit button as been entered.
<form>
Full Name:<input required type="text" name="fullname" action="currentFile.php"/>
<input type="submit"/>
</form>
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();                                      
$mail->Host = 'smtp.gmail.com';  
$mail->SMTPAuth = true;                                
$mail->Username = 'mail@gmail.com';                 
$mail->Password = 'pass';                          
$mail->SMTPSecure = 'tls';                             
$mail->Port = 587;                                    
$mail->addAddress('mail@gmail.com');     
$mail->Subject = 'Contact Form';
$mail->Body    = "Test";
$mail->AltBody = "Test";
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>
Would appreciate it if someone could explain how to make it so the php above only executes when the form is filled and button is clicked. Thank you.
