Change AddAddress to AddBCC and improved some of the comments.

Multiple email addresses not working when sending to mailgun using AddAddress. After changing it to AddBCC it resolved the problem for mailgun.
This commit is contained in:
FusionPBX 2021-08-16 11:25:49 -06:00 committed by GitHub
parent 2b8d011321
commit aca358c0b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 22 deletions

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2019 Portions created by the Initial Developer are Copyright (C) 2008-2021
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
@ -140,7 +140,7 @@
} }
//prepare smtp server settings //prepare smtp server settings
// load default smtp settings //load default smtp settings
if ($_SESSION['email']['smtp_hostname']['text'] != '') { if ($_SESSION['email']['smtp_hostname']['text'] != '') {
$smtp['hostname'] = $_SESSION['email']['smtp_hostname']['text']; $smtp['hostname'] = $_SESSION['email']['smtp_hostname']['text'];
} }
@ -165,7 +165,7 @@
$smtp['from_name'] = $_SESSION['voicemail']['smtp_from_name']['text']; $smtp['from_name'] = $_SESSION['voicemail']['smtp_from_name']['text'];
} }
// overwrite with domain-specific smtp server settings, if any //overwrite with domain-specific smtp server settings, if any
if (is_uuid($headers["X-FusionPBX-Domain-UUID"])) { if (is_uuid($headers["X-FusionPBX-Domain-UUID"])) {
$sql = "select domain_setting_subcategory, domain_setting_value "; $sql = "select domain_setting_subcategory, domain_setting_value ";
$sql .= "from v_domain_settings "; $sql .= "from v_domain_settings ";
@ -184,7 +184,7 @@
} }
unset($sql, $parameters, $result, $row); unset($sql, $parameters, $result, $row);
} }
// value adjustments //value adjustments
$smtp['auth'] = ($smtp['auth'] == "true") ? true : false; $smtp['auth'] = ($smtp['auth'] == "true") ? true : false;
$smtp['password'] = ($smtp['password'] != '') ? $smtp['password'] : null; $smtp['password'] = ($smtp['password'] != '') ? $smtp['password'] : null;
$smtp['secure'] = ($smtp['secure'] != "none") ? $smtp['secure'] : null; $smtp['secure'] = ($smtp['secure'] != "none") ? $smtp['secure'] : null;
@ -193,6 +193,8 @@
//send the email //send the email
include_once "resources/phpmailer/class.phpmailer.php"; include_once "resources/phpmailer/class.phpmailer.php";
include_once "resources/phpmailer/class.smtp.php"; include_once "resources/phpmailer/class.smtp.php";
//create the mail object
$mail = new PHPMailer(); $mail = new PHPMailer();
if (isset($_SESSION['email']['method'])) { if (isset($_SESSION['email']['method'])) {
switch ($_SESSION['email']['method']['text']) { switch ($_SESSION['email']['method']['text']) {
@ -206,21 +208,21 @@
$mail->IsSMTP(); $mail->IsSMTP();
} }
// optional bypass TLS certificate check e.g. for self-signed certificates //optional bypass TLS certificate check e.g. for self-signed certificates
if (isset($_SESSION['email']['smtp_validate_certificate'])) { if (isset($_SESSION['email']['smtp_validate_certificate'])) {
if ($_SESSION['email']['smtp_validate_certificate']['boolean'] == "false") { if ($_SESSION['email']['smtp_validate_certificate']['boolean'] == "false") {
// this is needed to work around TLS certificate problems
// this is needed to work around TLS certificate problems $mail->SMTPOptions = array(
$mail->SMTPOptions = array( 'ssl' => array(
'ssl' => array( 'verify_peer' => false,
'verify_peer' => false, 'verify_peer_name' => false,
'verify_peer_name' => false, 'allow_self_signed' => true
'allow_self_signed' => true )
) );
); }
}
} }
//smtp connection details
$mail->SMTPAuth = $smtp['auth']; $mail->SMTPAuth = $smtp['auth'];
if (isset($smtp['hostname'])) { if (isset($smtp['hostname'])) {
$mail->Hostname = $smtp['hostname']; $mail->Hostname = $smtp['hostname'];
@ -236,7 +238,7 @@
} }
$mail->SMTPDebug = 2; $mail->SMTPDebug = 2;
//send context to the temp log //add informaiton to the log
if (sizeof($headers)>0) { if (sizeof($headers)>0) {
foreach ($headers as $header => $value) { foreach ($headers as $header => $value) {
echo $header.": ".$value."\n"; echo $header.": ".$value."\n";
@ -259,7 +261,9 @@
} }
$mail->Subject = $subject; $mail->Subject = $subject;
$to = trim($to, "<> "); //add the reciepients
$to = trim($to, "<>");
$to = str_replace(" ", $to);
$to = str_replace(";", ",", $to); $to = str_replace(";", ",", $to);
$to_array = explode(",", $to); $to_array = explode(",", $to);
if (count($to_array) == 0) { if (count($to_array) == 0) {
@ -269,7 +273,7 @@
foreach ($to_array as $to_row) { foreach ($to_array as $to_row) {
if (strlen($to_row) > 0) { if (strlen($to_row) > 0) {
echo "Add Address: $to_row\n"; echo "Add Address: $to_row\n";
$mail->AddAddress(trim($to_row)); $mail->AddBCC(trim($to_row));
} }
} }
} }
@ -291,6 +295,7 @@
//inline //inline
$bodypart = $parts_array["BodyPart"]; $bodypart = $parts_array["BodyPart"];
$bodylength = $parts_array["BodyLength"]; $bodylength = $parts_array["BodyLength"];
if (strlen($file) > 0) { if (strlen($file) > 0) {
//get the file information //get the file information
$file_ext = pathinfo($file, PATHINFO_EXTENSION); $file_ext = pathinfo($file, PATHINFO_EXTENSION);
@ -342,7 +347,7 @@
$mail->isHTML(true); $mail->isHTML(true);
} }
else { else {
// $mail->Body = ($body != '') ? $body : $body_plain; //$mail->Body = ($body != '') ? $body : $body_plain;
$mail->Body = $body_plain."\n\n$transcription"; $mail->Body = $body_plain."\n\n$transcription";
$mail->AltBody = $body_plain."\n\n$transcription"; $mail->AltBody = $body_plain."\n\n$transcription";
$mail->isHTML(false); $mail->isHTML(false);
@ -359,7 +364,7 @@
echo "Retained in v_email_logs \n"; echo "Retained in v_email_logs \n";
} }
else { else {
// log/store message in database for review //log the message in database for review
if (!isset($email_log_uuid)) { if (!isset($email_log_uuid)) {
//build insert array //build insert array
$email_log_uuid = uuid(); $email_log_uuid = uuid();
@ -372,15 +377,18 @@
$array['email_logs'][0]['type'] = $headers["X-FusionPBX-Email-Type"]; $array['email_logs'][0]['type'] = $headers["X-FusionPBX-Email-Type"];
$array['email_logs'][0]['status'] = 'failed'; $array['email_logs'][0]['status'] = 'failed';
$array['email_logs'][0]['email'] = str_replace("'", "''", $msg); $array['email_logs'][0]['email'] = str_replace("'", "''", $msg);
//grant temporary permissions //grant temporary permissions
$p = new permissions; $p = new permissions;
$p->add('email_log_add', 'temp'); $p->add('email_log_add', 'temp');
//execute insert //execute insert
$database = new database; $database = new database;
$database->app_name = 'v_mailto'; $database->app_name = 'v_mailto';
$database->app_uuid = 'ba41954e-9d21-4b10-bbc2-fa5ceabeb184'; $database->app_uuid = 'ba41954e-9d21-4b10-bbc2-fa5ceabeb184';
$database->save($array); $database->save($array);
unset($array); unset($array);
//revoke temporary permissions //revoke temporary permissions
$p->delete('email_log_add', 'temp'); $p->delete('email_log_add', 'temp');
} }
@ -424,4 +432,4 @@
fclose($fp); fclose($fp);
*/ */
?> ?>