Use the send_email function to send fax to email.

This commit is contained in:
FusionPBX 2022-02-04 16:01:27 -07:00 committed by GitHub
parent 18512a80c1
commit 4f6e5da0af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 69 additions and 135 deletions

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2018
Portions created by the Initial Developer are Copyright (C) 2008-2022
the Initial Developer. All Rights Reserved.
Contributor(s):
@ -388,64 +388,16 @@ if (!function_exists('fax_split_dtmf')) {
unset($sql, $parameters, $result);
//prepare smtp server settings
// load default smtp settings
$smtp['method'] = $_SESSION['email']['smtp_method']['text'];
$smtp['host'] = (strlen($_SESSION['email']['smtp_host']['text'])?$_SESSION['email']['smtp_host']['text']:'127.0.0.1');
if (isset($_SESSION['email']['smtp_port'])) {
$smtp['port'] = (int)$_SESSION['email']['smtp_port']['numeric'];
}
else {
$smtp['port'] = 0;
}
$smtp['secure'] = $_SESSION['email']['smtp_secure']['text'];
$smtp['auth'] = $_SESSION['email']['smtp_auth']['text'];
$smtp['username'] = $_SESSION['email']['smtp_username']['text'];
$smtp['password'] = $_SESSION['email']['smtp_password']['text'];
$smtp['from'] = $_SESSION['email']['smtp_from']['text'];
$smtp['from_name'] = $_SESSION['email']['smtp_from_name']['text'];
$email_from = $_SESSION['email']['smtp_from']['text'];
$email_from_name = $_SESSION['email']['smtp_from_name']['text'];
if (isset($_SESSION['fax']['smtp_from']['text']) && strlen($_SESSION['fax']['smtp_from']['text']) > 0) {
$smtp['from'] = $_SESSION['fax']['smtp_from']['text'];
$email_from = $_SESSION['fax']['smtp_from']['text'];
}
if (isset($_SESSION['fax']['smtp_from_name']['text']) && strlen($_SESSION['fax']['smtp_from_name']['text']) > 0) {
$smtp['from_name'] = $_SESSION['fax']['smtp_from_name']['text'];
$email_from_name = $_SESSION['fax']['smtp_from_name']['text'];
}
// overwrite with domain-specific smtp server settings, if any
if (is_uuid($domain_uuid)) {
$sql = "select ";
$sql .= "domain_setting_subcategory, ";
$sql .= "domain_setting_value ";
$sql .= "from v_domain_settings ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ( ";
$sql .= "domain_setting_category = 'email' ";
$sql .= "or domain_setting_category = 'fax' ";
$sql .= ") ";
$sql .= "and domain_setting_name = 'text' ";
$sql .= "and domain_setting_enabled = 'true' ";
$parameters['domain_name'] = $domain_name;
$database = new database;
$result = $database->select($sql, $parameters, 'all');
if (is_array($result) && @sizeof($result) != 0) {
foreach ($result as $row) {
if ($row['domain_setting_value'] != '') {
$smtp[str_replace('smtp_','',$row["domain_setting_subcategory"])] = $row['domain_setting_value'];
}
}
}
unset($sql, $parameters, $result, $row);
}
// value adjustments
$smtp['method'] = ($smtp['method'] == '') ? 'smtp' : $smtp['method'];
$smtp['auth'] = ($smtp['auth'] == "true") ? true : false;
$smtp['password'] = ($smtp['password'] != '') ? $smtp['password'] : null;
$smtp['secure'] = ($smtp['secure'] != "none") ? $smtp['secure'] : null;
$smtp['username'] = ($smtp['username'] != '') ? $smtp['username'] : null;
//get the fax details from the database
//get the fax settings from the database
$sql = "select * from v_fax ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and fax_extension = :fax_extension ";
@ -592,101 +544,83 @@ if (!function_exists('fax_split_dtmf')) {
//send the email
if (strlen($fax_email) > 0 && file_exists($fax_file)) {
//prepare the message
$tmp_subject = (($fax_email_inbound_subject_tag != '') ? "[".$fax_email_inbound_subject_tag."]" : "Fax Received").": ".$fax_file_name;
$tmp_text_html = "<br><strong>Fax Received</strong><br><br>";
$tmp_text_html .= "Name: ".$fax_file_name."<br>";
$tmp_text_html .= "Extension: ".$fax_extension."<br>";
$tmp_text_html .= "Messages: ".$fax_messages."<br>";
$tmp_text_html .= $fax_file_warning."<br>";
//get the language code
$language_code = $_SESSION['domain']['language']['code'];
//get the template subcategory
if ($fax_relay == 'yes') {
$tmp_subject = "Fax Received for Relay: ".$fax_file_name;
$tmp_text_html .= "<br>This message arrived successfully from your fax machine, and has been queued for outbound fax delivery. You will be notified later as to the success or failure of this fax.<br>";
}
$tmp_text_plain = strip_tags(str_replace("<br>", "\n", $tmp_text_html));
//prepare the mail object
$mail = new PHPMailer();
if (isset($smtp['method'])) {
switch($smtp['method']) {
case 'sendmail': $mail->IsSendmail(); break;
case 'qmail': $mail->IsQmail(); break;
case 'mail': $mail->IsMail(); break;
default: $mail->IsSMTP(); break;
}
$template_subcategory = 'relay';
}
else {
$mail->IsSMTP(); // set mailer to use SMTP
$template_subcategory = 'inbound';
}
//optionally skip certificate validation
if (isset($_SESSION['email']['smtp_validate_certificate'])) {
if ($_SESSION['email']['smtp_validate_certificate']['boolean'] == "false") {
// this works around TLS certificate problems e.g. self-signed certificates
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//get the email template from the database
if (isset($email_address) && strlen($email_address) > 0) {
$sql = "select template_subject, template_body from v_email_templates ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and template_language = :template_language ";
$sql .= "and template_category = :template_category ";
$sql .= "and template_subcategory = :template_subcategory ";
$sql .= "and template_type = :template_type ";
$sql .= "and template_enabled = 'true' ";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['template_language'] = $language_code;
$parameters['template_category'] = 'fax';
$parameters['template_subcategory'] = $template_subcategory;
$parameters['template_type'] = 'html';
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row)) {
$email_subject = $row['template_subject'];
$email_body = $row['template_body'];
}
unset($sql, $parameters);
}
if ($smtp['auth'] == "true") {
$mail->SMTPAuth = $smtp['auth']; // turn on/off SMTP authentication
}
$mail->Host = $smtp['host'];
if (strlen($smtp['port']) > 0) {
$mail->Port = $smtp['port'];
}
if (strlen($smtp['secure']) > 0 && $smtp['secure'] != 'none') {
$mail->SMTPSecure = $smtp['secure'];
}
if ($smtp['username'] != '') {
$mail->Username = $smtp['username'];
$mail->Password = $smtp['password'];
}
$mail->SMTPDebug = 2;
$mail->From = $smtp['from'];
$mail->FromName = $smtp['from_name'];
$mail->Subject = $tmp_subject;
$mail->AltBody = $tmp_text_plain;
$mail->MsgHTML($tmp_text_html);
//replace variables in email subject
$email_subject = str_replace('${domain_name}', $_SESSION['domain_name'], $email_subject);
$email_subject = str_replace('${fax_file_name}', $fax_file_name, $email_subject);
$email_subject = str_replace('${fax_extension}', $fax_extension, $email_subject);
$email_subject = str_replace('${fax_messages}', $fax_messages, $email_subject);
$email_subject = str_replace('${fax_file_warning}', $fax_file_warning, $email_subject);
$email_subject = str_replace('${fax_subject_tag}', $fax_email_inbound_subject_tag, $email_subject);
$tmp_to = $fax_email;
$tmp_to = str_replace(";", ",", $tmp_to);
$tmp_to_array = explode(",", $tmp_to);
foreach($tmp_to_array as $tmp_to_row) {
if (strlen($tmp_to_row) > 0) {
echo "tmp_to_row: $tmp_to_row\n";
$mail->AddAddress(trim($tmp_to_row));
}
//replace variables in email body
$email_body = str_replace('${domain_name}', $_SESSION['domain_name'], $email_body);
$email_body = str_replace('${fax_file_name}', $fax_file_name, $email_body);
$email_body = str_replace('${fax_extension}', $fax_extension, $email_body);
$email_body = str_replace('${fax_messages}', $fax_messages, $email_body);
$email_body = str_replace('${fax_file_warning}', $fax_file_warning, $email_body);
$email_body = str_replace('${fax_subject_tag}', $fax_email_inbound_subject_tag, $email_body);
//debug info
//echo "<hr />\n";
//echo "email_address ".$fax_email."<br />\n";
//echo "email_subject ".$email_subject."<br />\n";
//echo "email_body ".$email_body."<br />\n";
//echo "<hr />\n";
//send the email
if (isset($fax_email) && strlen($fax_email) > 0) {
//add the attachment
$email_attachments[0]['type'] = 'file';
$email_attachments[0]['name'] = $fax_file_name;
$email_attachments[0]['value'] = $fax_file;
//$email_response = send_email($email_address, $email_subject, $email_body);
$email_response = !send_email($fax_email, $email_subject, $email_body, $email_error, $email_from_address, $email_from_name, 3, 3, $email_attachments) ? false : true;
}
//output to the log
echo "smtp_host: ".$smtp['host']."\n";
echo "smtp_from: ".$smtp['from']."\n";
echo "smtp_from_name: ".$smtp['from_name']."\n";
echo "tmp_subject: $tmp_subject\n";
//add the attachments
if (strlen($fax_file_name) > 0) {
if ($pdf_file && file_exists($pdf_file)) {
$mail->AddAttachment($pdf_file); // pdf attachment
}
else {
$mail->AddAttachment($fax_file); // tif attachment
}
//$filename='fax.tif'; $encoding = "base64"; $type = "image/tif";
//$mail->AddStringAttachment(base64_decode($strfax),$filename,$encoding,$type);
}
echo "email_from: ".$email_from."\n";
echo "email_from_name: ".$email_from_address."\n";
echo "email_subject: $email_subject\n";
//send the email
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
if ($email_response) {
echo "Mailer Error";
$email_status=$mail;
}
else {