I run into situation where I need to wrap php mailer inside my own function A, this function needs to return true or false if mail was successfully sent or not and another function B will still check if A returned true and do a few things or echo to user that mail was not sent if false. In other words, I need to do other things after sending email and I need to handle the success or failure myself. But once phpmailer sends mail, it hurriedly terminates the whole code and echoes sth to user and other functions won't execute.
Asked
Active
Viewed 86 times
1 Answers
1
You can put the if
condition for the send()
function and call the necessary methods inside that.
For example
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setFrom('from@example.com', 'Your Name');
$mail->addAddress('myfriend@example.net', 'My Friend');
$mail->Subject = 'First PHPMailer Message';
$mail->Body = 'Hi! This is my first e-mail sent through PHPMailer.';
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}

VinuBibin
- 679
- 8
- 19