Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/309947-button-to-submit-a-phpmailer-php-script/
Share on other sites

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?

@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 by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.