JonnyDriller Posted January 29, 2020 Share Posted January 29, 2020 I'm having problems creating a working submit button for a php script. The script is sitting on index.php and if I browse to that page it will send the email as required... great. So I though happy days I'll make a simple button for it... 6 hours later no joking. Firstly this is working php <?php require 'includes/PHPMailer.php'; require 'includes/SMTP.php'; require 'includes/Exception.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = "true"; $mail->SMTPSecure = "tls"; $mail->Port = "587"; $mail->Username = "Myemail@gmail.com"; $mail->Password = "Pass"; $mail->Subject = "Test email using PhPmailer"; $mail->setFrom("Myemail@gmail.com"); $mail->isHTML(true); $mail->addAttachment('img/LifesaverFootage.mp4'); $mail->Body = "<h1>This is a HTML heading</h1></br><p>Title</p>"; $mail->addAddress("myemail@gmail.com"); if ($mail->Send() ) { echo "Email sent..!"; } else{ echo "Error..!"; } $mail->smtpClose(); ?> Now I've been at this with everything but a blow torch these are some attempts below. I've also tried to just href to the page. All that happens is it creates another copy of the index.php file as if it were a download. The last thing I wanted to do was wrap this up as a function and I wanted to try something to do with Isset. But it won't even load the page if I define it as a function and then call it. I know I'm defining and calling the function correctly as I can do an echo function. Surely it couldn't be this hard. I mean all the thing has to do is dang trigger the page for goodness sake. Lol sighhhhhhh...Please help <!-- <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Email Button</title> </head> <body> <form action="index.php" method="get"> <input type="hidden" name="act" value="run"> <input type="submit" value="Run me now!"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
JonnyDriller Posted January 29, 2020 Author Share Posted January 29, 2020 I've tried a few variations with post as well as get too. Quote Link to comment Share on other sites More sharing options...
requinix Posted January 29, 2020 Share Posted January 29, 2020 What is the URL in your address bar when you browse to index.php directly? What is the URL in your address bar when you go to the page containing that form? Do you see any differences between the two other than the name of the file at the very end - and I do mean literally anything different other than that? Quote Link to comment Share on other sites More sharing options...
JonnyDriller Posted January 29, 2020 Author Share Posted January 29, 2020 (edited) @requinix- Hi Requinix thx for the reply. I was beginning to think I had a internet smell. To my great relief during the course of the troubleshooting I was doing for you, I managed to get it working! I've used a simple script, which I posted at the bottom for anyone in future, who might view the thread. As a side note one of the troubleshooting steps I was trying yesterday was - to define the script as a function. Why doesn't this load? It just gives me error 500. As far as I can tell it's the right syntax. I know the script inside the function works and I know this syntax works? What am I missing? <?php function EmailScript() { require 'includes/PHPMailer.php'; require 'includes/SMTP.php'; require 'includes/Exception.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = "true"; $mail->SMTPSecure = "tls"; $mail->Port = "587"; $mail->Username = "***********@gmail.com"; $mail->Password = "***********"; $mail->Subject = "Test email using PhPmailer"; $mail->setFrom("*********@gmail.com"); $mail->isHTML(true); //$mail->addAttachment('img/LifesaverFootage.mp4'); $mail->Body = "<h1>This is a HTML heading</h1></br><p>This is a html title</p>"; $mail->addAddress("lifesaversecur@gmail.com"); if ($mail->Send() ) { echo "Email sent..!"; } else{ echo "Error..!"; } $mail->smtpClose(); } EmailScript(); ?> Here's the working script for anyone in future: - just put the EmailButton.html in the same directory as the php loading from index.php or make them on the same page and adjust the code. <html> <body> <form action="index.php" method="POST"> <button type="submit">Send</button> </form> </body> </html> Edited January 29, 2020 by Barand Quote Link to comment Share on other sites More sharing options...
JonnyDriller Posted January 29, 2020 Author Share Posted January 29, 2020 Yeh I know... I changed it it's ok.. n00b move lol 🤔 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.