glFusion / glfusion

glFusion CMS - Advanced Content Management with Style
https://www.glfusion.org
GNU General Public License v2.0
3 stars 0 forks source link

Sending mail to user isn't working #367

Closed leegarner closed 2 years ago

leegarner commented 4 years ago

COM_emailNotification() expects destination names/addresses in an associative array, but sending mail to a single user uses the results of COM_formatEmailAddress(). This change may not be the right method, but fixes this particular issue without messing up other functions.


+++ b/public_html/admin/mail.php
@@ -243,7 +243,8 @@ function MAIL_sendMessages($vars)
                     array(Database::INTEGER)
         );
         if ($record !== false && $record !== null) {
-            $toUsers[] = COM_formatEmailAddress ($record['username'],$record['email']);
+            $tmp = COM_formatEmailAddress ($record['username'],$record['email']);
+            $toUsers[] = array('email' => $tmp[0], 'name' => $tmp[1]);
         }
     } else {
         $groupList = implode (',', USER_getChildGroups((int) COM_applyFilter($vars['to_group'],true)));```
walterrowe commented 4 years ago

MAIL_sendMessages() in mail.php uses COM_mail() at lines 285-295:

    foreach ($toUsers AS $to ) {
        if ( defined('DEMO_MODE') ) {
            $successes[] = htmlspecialchars ($to[0]);
        } else {
            if (!COM_mail ($to, $subject, $message, $from, $html, $priority)) {
                $failures[] = htmlspecialchars ($to[0]);
            } else {
                $successes[] = htmlspecialchars ($to[0]);
            }
        }
    }

COM_mail processes $to as follows in lib-common.php at lines 2639-2654:

    if ( is_array($to) && isset($to[0]) && $to[0] != '' ) {
        if ( isset($to[1]) && $to[1] != '' ) {
            if ( filter_var($to[0], FILTER_VALIDATE_EMAIL) ) {
                $mail->AddAddress($to[0],$to[1]);
            }
        } else {
            if ( filter_var($to[0], FILTER_VALIDATE_EMAIL) ) {
                $mail->AddAddress($to[0]);
            }
        }
    } else {
        // assume old style....
        if ( filter_var($to, FILTER_VALIDATE_EMAIL) ) {
            $mail->AddAddress($to);
        }
    }
leegarner commented 4 years ago

FYI, this is related to the 2.0.0 branch, in 1.7.x COM_emailNotification isn't available yet

walterrowe commented 4 years ago

Ah. Righto. Your proposed code would appear to resolve the issue in 2.0.0.

leegarner commented 4 years ago

Yes, should have clarified, I'm only seeing the issue in 2.0.