My PHPMailer script is not working for the form here. I am using Gmail SMTP. The form does not have attachment option so i disabled it. Please note I have replaced SMTP login info, from email and to email with dummy emails only for the purpose of posting on stackoverflow. BTW, could it have anything to do with the absolute url to the autoload.php file?
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require content_url('/phpmailer/vendor/autoload.php');
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 1; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'example@gmail.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('example2@gmail.com', 'example2');
$mail->addAddress('example3@gmail.com'); // Add a recipient
//Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Application form submission';
$mail->Body = $message;
$mail->AltBody = strip_tags($message);
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
Can anyone tell me why it isn't working?
I am getting the following errors:-
Notice: Undefined index: income_checkbox in /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 495
Warning: require(): https:// wrapper is disabled in the server configuration by allow_url_include=0 in /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 5164
Warning: require(https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php): failed to open stream: no suitable wrapper could be found in /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 5164
Fatal error: require(): Failed opening required 'https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php' (include_path='.:/usr/share/pear/php:/usr/share/php:/usr/share/pear') in /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 5164