Trying to fix email sending

This commit is contained in:
Finley Ghosh 2025-11-20 22:50:02 +11:00
parent f873d51c86
commit 96bf160198
2 changed files with 15 additions and 10 deletions

View file

@ -1211,7 +1211,7 @@ EOT;
if (!preg_match('/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/', $email)) { if (!preg_match('/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/', $email)) {
return ''; return '';
} }
return "$email <$email>"; return $email;
} }
function parse_email_to_array($input) { function parse_email_to_array($input) {
@ -1326,7 +1326,8 @@ function email_pdf_with_custom_recipients($id = null, $to = null, $cc = null, $b
echo json_encode(array('success' => false, 'message' => $msg)); echo json_encode(array('success' => false, 'message' => $msg));
return; return;
} else { } else {
$this->Email->to = implode(', ', $toArray); // Pass as array - modified CakePHP EmailComponent now supports arrays for TO field
$this->Email->to = $toArray;
} }
$ccArray = $this->parse_email_to_array($cc); $ccArray = $this->parse_email_to_array($cc);
if (!empty($ccArray)) { if (!empty($ccArray)) {

View file

@ -712,9 +712,13 @@ class EmailComponent extends Object{
return false; return false;
} }
if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($this->to, true))) { // Handle both single email (string) and multiple emails (array) for TO field
$toRecipients = is_array($this->to) ? $this->to : array($this->to);
foreach ($toRecipients as $to) {
if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($to, true))) {
return false; return false;
} }
}
foreach ($this->cc as $cc) { foreach ($this->cc as $cc) {
if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($cc, true))) { if (!$this->__smtpSend('RCPT TO: ' . $this->__formatAddress($cc, true))) {