News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

while doesnt work

Started by Jotade29, December 16, 2022, 07:04:22 PM

Previous topic - Next topic

Jotade29

Hello, I have made another function in subs-post, which is like sendmail, but configured with phpmailer. The issue is that the function works perfectly, and sends me all the emails (smtp). Only, in one part I can't get it to work, and the loop breaks...

The function is as follows -> function sendmailT($to, $subject, $message, $from = null, $message_id = null)

The part that I can't get it to work, because the while loop breaks, is in SendTopic.php, in the section that sends an email when a post report is received...


// Send every moderator an email.

$request = $smcFunc['db_query']('', '
SELECT id_member, email_address, lngfile, mod_prefs
FROM {db_prefix}members
WHERE id_member IN ({array_int:moderator_list})
AND notify_types != {int:notify_types}
ORDER BY lngfile',
array(
'moderator_list' => $moderators,
'notify_types' => 4,
)
);

while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Maybe they don't want to know?!
if (!empty($row['mod_prefs']))
{
list(,, $pref_binary) = explode('|', $row['mod_prefs']);
if (!($pref_binary & 1) && (!($pref_binary & 2) || !in_array($row['id_member'], $real_mods)))
continue;
}

$replacements = array(
'TOPICSUBJECT' => $subject,
'POSTERNAME' => $poster_name,
'REPORTERNAME' => $reporterName,
'TOPICLINK' => $scripturl . '?topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg'],
'REPORTLINK' => !empty($id_report) ? $scripturl . '?action=moderate;area=reports;report=' . $id_report : '',
'COMMENT' => $_POST['comment'],
);

$emaildata = loadEmailTemplate('report_to_moderator', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);

// Send it to the moderator.
sendmailT($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null);
}
$smcFunc['db_free_result']($request);

The result is that the screen goes blank when sending the report. I have done a print_r of $row[email_adrees] and it shows me the emails correctly of all the staffs in the following way: [email protected]@[email protected]... I always receive the email in the first email that is shown, in this case [email protected], but not in the rest. After the sendmailT function, I do a break, and then it sends it to me again only to the first of all, but this time it loads me, and tells me that the report was sent successfully, that's why I understand that the error is produced by the rest of emails.

How can I correctly make a loop for row[email_address] and only exit it when I have entered all the emails?

My version is 2.0.19. Thanks.
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Aleksi "Lex" Kilpinen

I don't honestly understand what you are trying to do that SMF doesn't already do?
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

vbgamer45

Maybe they don't have notificatoins enabled?
// Maybe they don't want to know?!
if (!empty($row['mod_prefs']))
{
list(,, $pref_binary) = explode('|', $row['mod_prefs']);
if (!($pref_binary & 1) && (!($pref_binary & 2) || !in_array($row['id_member'], $real_mods)))
continue;
}

That part checks.


I would do a print_r() in the start of the loop and see if all the people you want to receive the mail are there.
And maybe the same after the  if (!empty($row['mod_prefs'])) so you can compare.
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

live627

SMF supports SMTP.

Looks like the issue stems from
Quote from: Jotade29 on November 25, 2022, 02:28:15 PMVersion 2.0.19; php default function
Hi, when sending the email to recover the password, the servers do not receive it, nor does hotmail, gmail... the same thing happens with any function that sends an email. But if the receiving account is an account on my server, it receives the mail. On the host I have everything enabled, and it tells me that the mail was sent perfectly, but I never receive it. Is there a problem?

Jotade29

Quote from: Aleksi "Lex" Kilpinen on December 17, 2022, 03:59:55 AMI don't honestly understand what you are trying to do that SMF doesn't already do?

Thanks for answering, in my case, the emails are not received, so I had to modify the said function to adapt it to PHPMailer, and configure it to SMTP, in this way I receive them correctly.

Quote from: vbgamer45 on December 17, 2022, 08:36:02 AMMaybe they don't have notificatoins enabled?
// Maybe they don't want to know?!
if (!empty($row['mod_prefs']))
{
list(,, $pref_binary) = explode('|', $row['mod_prefs']);
if (!($pref_binary & 1) && (!($pref_binary & 2) || !in_array($row['id_member'], $real_mods)))
continue;
}

That part checks.


I would do a print_r() in the start of the loop and see if all the people you want to receive the mail are there.
And maybe the same after the  if (!empty($row['mod_prefs'])) so you can compare.
Thnx for answering!!!
I did that too, that is, when I have to debug code, I try to remove any conditionals and leave only the necessary function. Although this function is left alone in sendmail, it stays blank, and is not able to send the emails

Quote from: live627 on December 17, 2022, 09:58:13 PMSMF supports SMTP.

Looks like the issue stems from
Quote from: Jotade29 on November 25, 2022, 02:28:15 PMVersion 2.0.19; php default function
Hi, when sending the email to recover the password, the servers do not receive it, nor does hotmail, gmail... the same thing happens with any function that sends an email. But if the receiving account is an account on my server, it receives the mail. On the host I have everything enabled, and it tells me that the mail was sent perfectly, but I never receive it. Is there a problem?
Thanks por anwsering
In my case, the emails are sent correctly with the original function, but they are not received, not even in hotmail, outlook, icloud, gmail... That's why I had to adapt that function to phpmailer

Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Advertisement: