feat: Enhance email functionality and PDF generation for Sales Orders

- Enabled SMTP debugging in PHPMailer for better error tracking.
- Added a "Test send email" link in the Inventory Detail View for quick email testing.
- Implemented automatic PDF generation and email sending upon Sales Order creation.
- Created a new action for sending Sales Order emails with attached PDFs.
- Added a new AJAX action for testing outgoing email server configurations.
- Updated outgoing server settings to use new SMTP credentials.
- Improved email templates for better user experience.
- Added test scripts for validating PDF generation and email sending.
This commit is contained in:
BACHIR SOULDI
2026-02-17 15:59:31 +01:00
parent 2794e62571
commit 2a647b138a
46 changed files with 25100 additions and 1296 deletions

View File

@@ -0,0 +1,74 @@
<?php
/*+***********************************************************************************
* Custom Action for Outgoing Server Test Mail
*************************************************************************************/
class Settings_Vtiger_OutgoingServerAjax_Action extends Settings_Vtiger_Basic_Action
{
public function process(Vtiger_Request $request)
{
$outgoingServerSettingsModel = Settings_Vtiger_Systems_Model::getInstanceFromServerType('email', 'OutgoingServer');
$response = new Vtiger_Response();
try {
// Always send test mail
$sent = $this->sendTestMail($outgoingServerSettingsModel);
if ($sent) {
$data = $outgoingServerSettingsModel->getData();
$data['message'] = '✅ Configuration saved and test mail sent successfully.';
$data['success'] = true;
$response->setResult($data);
} else {
$response->setResult([
'success' => false,
'message' => '⚠️ Test mail failed to send. Check SMTP settings or logs.'
]);
}
} catch (Exception $e) {
$response->setError($e->getCode(), $e->getMessage());
}
// Important: emit and stop ALL further output
$response->emit();
exit; // 🔹 This prevents extra output after JSON
}
public function sendTestMail($model , $subject = null, $body = null,$pdf_path = null)
{
require_once 'vtlib/Vtiger/Mailer.php';
$mailer = new Vtiger_Mailer();
try {
$mailer->IsSMTP();
$mailer->Host = $model->get('server');
$mailer->Port = 587;
$mailer->SMTPAuth = $model->isSmtpAuthEnabled();
$mailer->Username = $model->get('server_username');
$mailer->Password = $model->get('server_password');
$mailer->SMTPSecure = 'tls';
$mailer->From = $model->get('from_email_field');
$mailer->FromName = 'Vtiger Test Mail';
$mailer->AddAddress($model->to_email ?? 'souldibachir3150@gmail.com');
$mailer->AddCC('andryamo2231@gmail.com');
$mailer->Subject = $subject ?? 'Test Mail from Vtiger CRM 2';
$mailer->IsHTML(true);
$mailer->Body = $body ?? 'This is a test mail sent when saving outgoing server configuration. 2'.$pdf_path;
// // Attach Sales Order PDF if available
// if (!empty($model->pdf_path) && file_exists($model->pdf_path)) {
// $mailer->AddAttachment($model->pdf_path, basename($model->pdf_path));
// }
if (!$mailer->Send(true)) {
error_log('SMTP send() failed: ' . $mailer->ErrorInfo);
return false;
}
return true;
} catch (Exception $e) {
error_log('SMTP Test Mail Error: ' . $e->getMessage());
return false;
}
}
}