Skip to content

Commit

Permalink
Save the email response (#6558)
Browse files Browse the repository at this point in the history
* Save the email response

* use the response variable from the email class

* Rename email_debug to email_response

* Update app_languages.php

* Show the email response

* Save the email response
  • Loading branch information
markjcrane committed Feb 17, 2023
1 parent 7dbfd22 commit 97dbe7b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 29 deletions.
5 changes: 4 additions & 1 deletion app/email_logs/email_test.php
Expand Up @@ -92,7 +92,6 @@
$email_from_name = $_SESSION['email']['smtp_from_name']['text'];

//send email
//ob_start();
//$sent = !send_email($email_recipient, 'Test Message', $email_body, $email_error, null, null, 3, 3, $email_attachments) ? false : true;
//$email_response = ob_get_clean();

Expand All @@ -107,8 +106,12 @@
$email->debug_level = 3;
$email->method = 'direct';
$sent = $email->send();
$email_response = $email->response;
//$email_error = $email->email_error;

//show the response
echo $email_response;

//show additional information
echo "<br><br>\n";

Expand Down
6 changes: 3 additions & 3 deletions app/email_queue/app_config.php
Expand Up @@ -5,7 +5,7 @@
$apps[$x]['uuid'] = '5befdf60-a242-445f-91b3-2e9ee3e0ddf7';
$apps[$x]['category'] = 'system';
$apps[$x]['subcategory'] = 'email';
$apps[$x]['version'] = '2.10';
$apps[$x]['version'] = '2.11';
$apps[$x]['license'] = 'Member';
$apps[$x]['url'] = 'http://www.fusionpbx.com';
$apps[$x]['description']['en-us'] = '';
Expand Down Expand Up @@ -163,8 +163,8 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['search_by'] = 'true';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = 'email_debug';
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = 'email_substatus';
$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = 'email_response';
$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = 'email_debug';
$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
//$apps[$x]['db'][$y]['fields'][$z]['search_by'] = 'true';
$z++;
Expand Down
20 changes: 20 additions & 0 deletions app/email_queue/app_languages.php
Expand Up @@ -461,6 +461,26 @@
$text['description-email_action_after']['sv-se'] = '';
$text['description-email_action_after']['uk-ua'] = '';

$text['label-email_response']['en-us'] = 'Response';
$text['label-email_response']['ar-eg'] = '';
$text['label-email_response']['de-at'] = '';
$text['label-email_response']['de-ch'] = '';
$text['label-email_response']['de-de'] = '';
$text['label-email_response']['es-cl'] = '';
$text['label-email_response']['es-mx'] = '';
$text['label-email_response']['fr-ca'] = '';
$text['label-email_response']['fr-fr'] = '';
$text['label-email_response']['he-il'] = '';
$text['label-email_response']['it-it'] = '';
$text['label-email_response']['nl-nl'] = '';
$text['label-email_response']['pl-pl'] = '';
$text['label-email_response']['pt-br'] = '';
$text['label-email_response']['pt-pt'] = '';
$text['label-email_response']['ro-ro'] = '';
$text['label-email_response']['ru-ru'] = '';
$text['label-email_response']['sv-se'] = '';
$text['label-email_response']['uk-ua'] = '';

$text['label-email_retry_count']['en-us'] = 'Retry';
$text['label-email_retry_count']['ar-eg'] = '';
$text['label-email_retry_count']['de-at'] = '';
Expand Down
24 changes: 11 additions & 13 deletions app/email_queue/email_queue_edit.php
Expand Up @@ -165,7 +165,7 @@
$email_status = $row["email_status"];
$email_retry_count = $row["email_retry_count"];
//$email_action_before = $row["email_action_before"];
$email_debug = $row["email_debug"];
$email_response = $row["email_response"];
$email_action_after = $row["email_action_after"];
}
unset($sql, $parameters, $row);
Expand Down Expand Up @@ -313,18 +313,16 @@
echo "</td>\n";
echo "</tr>\n";

if (isset($_REQUEST['debug'])) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-email_debug']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <textarea class='formfld' style='width: 450px; height: 100px;' name='email_debug'>".$email_debug."</textarea>\n";
echo "<br />\n";
echo $text['description-email_debug']."\n";
echo "</td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-email_response']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <textarea class='formfld' style='width: 450px; height: 100px;' name='email_response'>".$email_response."</textarea>\n";
echo "<br />\n";
echo $text['description-email_response']."\n";
echo "</td>\n";
echo "</tr>\n";

echo "</table>";
echo "<br /><br />";
Expand Down
25 changes: 14 additions & 11 deletions app/email_queue/resources/jobs/email_send.php
Expand Up @@ -235,7 +235,6 @@ function remove_tags($string) {

//echo "email_body before: ".$email_body."\n";
$email_body = str_replace('${message_text}', $transcribe_message, $email_body);
//$email_debug = $field['message'];
//echo "email_body after: ".$email_body."\n";
//unset($field);
}
Expand Down Expand Up @@ -286,11 +285,8 @@ function remove_tags($string) {
unset($parameters);
}

//send email
//ob_start();
//$sent = !send_email($email_to, $email_subject, $email_body, $email_error, null, null, null, null, $email_attachments) ? false : true;
//$response = ob_get_clean();
//echo $response;
//save output to a buffer
// ob_start();

//send the email
$email = new email;
Expand All @@ -301,12 +297,17 @@ function remove_tags($string) {
$email->subject = $email_subject;
$email->body = $email_body;
$email->attachments = $email_attachments;
$email->debug_level = 3;
$email->method = 'direct';
$email_response = $email->send();
$email_error = $email->email_error;
$email_status = $email->send();
$email_error = $email->error;
$email_response = $email->response;

//get the output buffer
// //$email_response = ob_get_clean();

//send the email
if ($email_response) {
if ($email_status) {

//set the email status to sent
$sql = "update v_email_queue ";
Expand All @@ -315,9 +316,11 @@ function remove_tags($string) {
if (isset($transcribe_message)) {
$sql .= "email_transcription = :email_transcription, ";
}
$sql .= "email_response = :email_response, ";
$sql .= "update_date = now() ";
$sql .= "where email_queue_uuid = :email_queue_uuid; ";
$parameters['email_queue_uuid'] = $email_queue_uuid;
$parameters['email_response'] = $email_response;
if (isset($transcribe_message)) {
$parameters['email_transcription'] = $transcribe_message;
}
Expand Down Expand Up @@ -437,12 +440,12 @@ function remove_tags($string) {
else {
$sql .= "set email_status = 'trying', ";
}
$sql .= "email_debug = :email_debug, ";
$sql .= "email_response = :email_response, ";
$sql .= "email_retry_count = :email_retry_count, ";
$sql .= "update_date = now() ";
$sql .= "where email_queue_uuid = :email_queue_uuid; ";
$parameters['email_queue_uuid'] = $email_queue_uuid;
$parameters['email_debug'] = $mailer_error;
$parameters['email_response'] = $email_response;
$parameters['email_retry_count'] = $email_retry_count;
$database = new database;
$database->execute($sql, $parameters);
Expand Down
11 changes: 10 additions & 1 deletion resources/classes/email.php
Expand Up @@ -561,8 +561,17 @@ public function send() {
}
}

//save output to a buffer
ob_start();

//send the email
$mail_status = $mail->Send();

//get the output buffer
$this->response = ob_get_clean();

//send the email
if (!$mail->Send()) {
if (!$mail_status) {
if (isset($mail->ErrorInfo) && strlen($mail->ErrorInfo) > 0) {
$this->error = $mail->ErrorInfo;
}
Expand Down

0 comments on commit 97dbe7b

Please sign in to comment.