Skip to content

Commit

Permalink
Mailer: Add SMTPOptions in PHPMailer, improve debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Apr 8, 2021
1 parent 625f184 commit a40cc04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
9 changes: 9 additions & 0 deletions app/config/mail.conf.dist.php
Expand Up @@ -19,6 +19,15 @@
$platform_email['SMTP_DEBUG'] = 0; // change to 1 to enable smtp debug
$platform_email['SMTP_SECURE'] = 'tls'; // if you're using SSL: ssl; or TLS: tls. (only used if SMTP_AUTH==1)
$platform_email['SMTP_UNIQUE_REPLY_TO'] = 0; // to use AWS SMS service, SMTP_UNIQUE_SENDER and this have to be = 1
// If you have certificate problems see:
// https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#updating-ca-certificates
/*$platform_email['SMTPOptions'] = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
];*/
// DKIM requires the generation of a public/private keypair and the configuration of a TXT record in your DNS
// The TXT record should look like this: chamilo._domainkey.yourdomain.ext IN TXT "v=1; k=rsa; s=chamilo; p=PubKey..."
// to match the following selector
Expand Down
29 changes: 18 additions & 11 deletions main/inc/lib/api.lib.php
Expand Up @@ -9229,6 +9229,7 @@ function api_mail_html(
$mail->CharSet = isset($platform_email['SMTP_CHARSET']) ? $platform_email['SMTP_CHARSET'] : 'UTF-8';
// Stay far below SMTP protocol 980 chars limit.
$mail->WordWrap = 200;
$mail->SMTPOptions = $platform_email['SMTPOptions'] ?? [];

if ($platform_email['SMTP_AUTH']) {
$mail->SMTPAuth = 1;
Expand Down Expand Up @@ -9386,19 +9387,25 @@ function api_mail_html(
}

// Send the mail message.
if (!$mail->Send()) {
$sent = $mail->Send();
if (!$sent) {
error_log('ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'<br />');
if ($mail->SMTPDebug) {
error_log(
"Connection details :: ".
"Protocol: ".$mail->Mailer.' :: '.
"Host/Port: ".$mail->Host.':'.$mail->Port.' :: '.
"Authent/Open: ".($mail->SMTPAuth ? 'Authent' : 'Open').' :: '.
($mail->SMTPAuth ? " User/Pass: ".$mail->Username.':'.$mail->Password : '').' :: '.
"Sender: ".$mail->Sender
);
}
}

if ($mail->SMTPDebug) {
error_log(
"Mail debug:: ".
"Protocol: ".$mail->Mailer.' :: '.
"Host/Port: ".$mail->Host.':'.$mail->Port.' :: '.
"Authent/Open: ".($mail->SMTPAuth ? 'Authent' : 'Open').' :: '.
($mail->SMTPAuth ? " User/Pass: ".$mail->Username.':'.$mail->Password : '').' :: '.
"Sender: ".$mail->Sender.
"Recipient email: ".$recipient_email.
"Subject: ".$subject
);
}

if (!$sent) {
return 0;
}

Expand Down

0 comments on commit a40cc04

Please sign in to comment.