I have PHP mail
code that is successfully sending the email message on page load, but i need to send it on form post of this same page. I have looked at other answers as i realize this is generally a pretty simple thing to do, but due to the specific code i am working with i was unable to solve my issue.
The page is part of an order entry system, and when the page loads, an email is sent to an admin to inform that an order has started. This currently works - but i need to include in this email the data the user has entered on the same page.
I am not asking for help with including the variables for the user data (i realize they are not in the mail
code yet), but just how to send the same mail
on click of the page's submit button.
You can see i tried to if(isset($_POST["submit"])){
unsuccessfully, but left it commented out.
What is the best way to send this mail
triggered by the HTML button below instead of on page load?
// PHP currently sending mail on page load
// if(isset($_POST["submit"])){
if ($_SESSION['sessfirstemailsent'] != 'yes')
{
$_SESSION['sessfirstemailsent'] = 'yes' ;
if ($_SESSION['sessorderformdatalogo'] == 'logo.jpg')
{
$logoimage = '<img alt="Proud Member of the US Family Guide Network" src="http://' . $_SESSION['sessorderformdatadomain'] . '/images/logo.jpg" class="img-fluid mx-auto" width="' . $logowidth . 'px"/>';
}
else
{
$logoimage= '<img alt="' . $_SESSION['sessorderformdatalogo'] . '" src="http://' . $_SESSION['sessorderformdatadomain'] . '/images/' . $_SESSION['sessorderformdatalogo'] .'" class="img-fluid mx-auto" width="' . $logowidth . 'px"/>';
}
$to = $sendadminemailto;
$from = 'info@USFamilyGuide.com';
$subject = 'New order start from ' . $_SESSION['sessorderformdatadomainblurb'];
$message = '<html><body>' . $logoimage . ' <br> ' . $emailmessage . $_SESSION['sessorderformdatadomainblurb'] . '<br /><br /></body></html>';
$headers = 'From: ' . $from . "\r\nContent-type: text/html\r\n";
mail($to, $subject, $message, $headers);
}
// }
<!-- HTML button i want to trigger the mail -->
<input class="btn-lg btn-primary float-right" type="submit" name="submit" value="Save & Continue"/>