- 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.
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
$recordId = 1020725; // the SalesOrder ID
|
|
|
|
$module = 'SalesOrder';
|
|
$loginUrl = "https://sophal.net/sophalcrm/index.php?module=Users&action=Login";
|
|
$exportUrl = "https://sophal.net/sophalcrm/index.php?module=SalesOrder&action=ExportPDF&record=$recordId";
|
|
|
|
// 1) Login
|
|
$post = http_build_query([
|
|
'username' => 'admin',
|
|
'password' => 'Sophal@Crm@Sophal',
|
|
]);
|
|
|
|
$contextLogin = stream_context_create([
|
|
'http' => [
|
|
'method' => 'POST',
|
|
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
|
|
'content' => $post,
|
|
]
|
|
]);
|
|
|
|
file_get_contents($loginUrl, false, $contextLogin);
|
|
|
|
// Extract session cookie
|
|
$cookies = [];
|
|
foreach ($http_response_header as $hdr) {
|
|
if (stripos($hdr, 'Set-Cookie:') === 0) {
|
|
$cookies[] = trim(substr($hdr, 11), ';');
|
|
}
|
|
}
|
|
$cookieHeader = 'Cookie: ' . implode('; ', $cookies);
|
|
|
|
// 2) Get PDF
|
|
$contextPDF = stream_context_create([
|
|
'http' => [
|
|
'method' => 'GET',
|
|
'header' => $cookieHeader
|
|
]
|
|
]);
|
|
|
|
$pdfContent = file_get_contents($exportUrl, false, $contextPDF);
|
|
|
|
// 3) Validate
|
|
if (strpos($pdfContent, '%PDF') !== 0) {
|
|
error_log("ExportPDF returned invalid PDF for record $recordId");
|
|
return;
|
|
}
|
|
|
|
// 4) Save
|
|
$filePath = $_SERVER['DOCUMENT_ROOT']."/sophalcrm/storage/SalesOrder_$recordId.pdf";
|
|
file_put_contents($filePath, $pdfContent);
|