Email Question
Posted: Sat Oct 21, 2023 7:59 pm
Good day,
I have a question about emailing with the built in PHP form processing.
The question is not how to write the script or how to use the PHPMailer that WWB uses internally as this is the PHPMailer library from the github site from what I can see in the code used.
This is a question about the order of things and when the email is actually being sent?
I have a form and have 7-8 fields in the form and in the PHP script I have validation checks for each field.
If say a required input is missing I call up a input_error webpage that outlines the error and takes the user back to the original input form to fix the error.
When I check off: "The Use built in PHP processor script", the email is triggered on a validation call to the PHP code with the email sending code in it. See beginning of the php code below with the function ValidateEmail($email)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require __DIR__.'/Exception.php';
require __DIR__.'/PHPMailer.php';
require __DIR__.'/SMTP.php';
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);[/size][/size]
My issue is this is called and by-passes the other validation code I have in the main form's PHP script.
So the beginning of my php script for the form is shown below . . .
<?php
session_start();
$mysql_server = 'localhost';
$mysql_username = 'appusers';
$mysql_password = 'xxxxxxxxxxxxxx';
$mysql_database = 'Pickups';
$mysql_table = 'cuslogin';
$success_page = './cus-VerifyAccnt.php';
$error_page = './cus-AccntFailed.php';
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'signupform')
{
$newusername = $_POST['username'];
$newemail = $_POST['email'];
$newpassword = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$newfullname = $_POST['fullname'];
$city = $_POST['city'];
$address = $_POST['address'];
$province = $_POST['province'];
$postalcode = $_POST['postalcode'];
$mobilephone = $_POST['mobilephone'];
$homephone = $_POST['homephone'];
$code = 'NA';
[/size][/size]
Example of my validation code for address . .
if (strlen($address) == 0)
{
$error_message = 'Address is missing and required!';
$_SESSION['errmsg'] = $error_message;
header('Location: '.$error_page);
}
Is there any trick that can be done so that the email function fires off after all my validation checks have been completed and then send the email?
I realize I can just cut and past the PHPMailer code where I want and rename the function and call it where I want, bu if I do that each time I generate the project my custom copy and paste code gets overwritten and I manually have to copy and paste again.
So is there a way in the WWB interface itself to change when the PHPMailer function call happens?
Pete,
I have a question about emailing with the built in PHP form processing.
The question is not how to write the script or how to use the PHPMailer that WWB uses internally as this is the PHPMailer library from the github site from what I can see in the code used.
This is a question about the order of things and when the email is actually being sent?
I have a form and have 7-8 fields in the form and in the PHP script I have validation checks for each field.
If say a required input is missing I call up a input_error webpage that outlines the error and takes the user back to the original input form to fix the error.
When I check off: "The Use built in PHP processor script", the email is triggered on a validation call to the PHP code with the email sending code in it. See beginning of the php code below with the function ValidateEmail($email)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require __DIR__.'/Exception.php';
require __DIR__.'/PHPMailer.php';
require __DIR__.'/SMTP.php';
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);[/size][/size]
My issue is this is called and by-passes the other validation code I have in the main form's PHP script.
So the beginning of my php script for the form is shown below . . .
<?php
session_start();
$mysql_server = 'localhost';
$mysql_username = 'appusers';
$mysql_password = 'xxxxxxxxxxxxxx';
$mysql_database = 'Pickups';
$mysql_table = 'cuslogin';
$success_page = './cus-VerifyAccnt.php';
$error_page = './cus-AccntFailed.php';
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'signupform')
{
$newusername = $_POST['username'];
$newemail = $_POST['email'];
$newpassword = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$newfullname = $_POST['fullname'];
$city = $_POST['city'];
$address = $_POST['address'];
$province = $_POST['province'];
$postalcode = $_POST['postalcode'];
$mobilephone = $_POST['mobilephone'];
$homephone = $_POST['homephone'];
$code = 'NA';
[/size][/size]
Example of my validation code for address . .
if (strlen($address) == 0)
{
$error_message = 'Address is missing and required!';
$_SESSION['errmsg'] = $error_message;
header('Location: '.$error_page);
}
Is there any trick that can be done so that the email function fires off after all my validation checks have been completed and then send the email?
I realize I can just cut and past the PHPMailer code where I want and rename the function and call it where I want, bu if I do that each time I generate the project my custom copy and paste code gets overwritten and I manually have to copy and paste again.
So is there a way in the WWB interface itself to change when the PHPMailer function call happens?
Pete,