I want some tutorial about phpmailer on CI 4. I had searched a lot and I didn't find it.
Laravel is popular and lots of resources
but now I just have done with the code below
thanks all
PHP Code:
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
public function send($users) {
require ROOTPATH.'/PHPMailer/src/Exception.php';
require ROOTPATH.'/PHPMailer/src/PHPMailer.php';
require ROOTPATH.'/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
try {
//Server settings
#$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = '192.168.1.219'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'PxAkdV%4MW'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
#$mail->SMTPSecure = 'tls';
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('[email protected]', 'Mailer');
$mail->Subject = "Thanks for your registration";
foreach ($users as $user) {
$mail->addAddress($user['email'], $user['name']);
$mail->Body = "<h2>Hello, {$user['name']}!</h2> <p>Thanks for your registeration,the application is being processed</p>";
$mail->AltBody = "Hello, {$user['name']}! \n Thanks for your registeration,the application is being processed";
try {
$mail->send();
//echo "Message sent to: ({$user['email']}) {$mail->ErrorInfo}\n";
} catch (Exception $e) {
//echo "Mailer Error ({$user['email']}) {$mail->ErrorInfo}\n";
}
$mail->clearAddresses();
}
$mail->smtpClose();
} catch (Exception $e) {
#echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}