1
Jack404
XoopsMultiMailer Problem!
  • 2004/5/8 19:33

  • Jack404

  • Just popping in

  • Posts: 56

  • Since: 2003/5/16


Part of my code for my site is as follows:

le="color: #000000"><?php [Begin Snippet] global $xoopsDB; global $xoopsUser; include_once XOOPS_ROOT_PATH.'/class/xoopsmailer.php'; include_once XOOPS_ROOT_PATH.'/class/mail/xoopsmultimailer.php'; $myts =& MyTextSanitizer::getInstance(); $xoopsMailer =& getMailer(); $sql = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13"'; $result = $xoopsDB->query($sql); $email = $result; $body = $myts->oopsStripSlashesGPC($_POST['mail_body']); $subject = $myts->oopsStripSlashesGPC($_POST['mail_subject']); $headers = "MIME-Version: 1.0rn"; $headers .= "Content-type: text/html; charset=iso-8859-1rn"; $sent = $xoopsMailer->sendMail($email, $subject, $body, $headers); if ($sent) { redirect_header('index.php',5,"Send mail complete!"); } else { $errors = $xoopsMailer->getErrors(); die('There was an error.<br>'.$errors); } exit(); [End Snippet]


The code fails every time I run it, and the error that I get is "SMTP Error: The following recipients failed [Resource id #26]"

I know this means that something's going wrong with the array of emails, but I'm not sure how to fix it. If anyone could help, I'd be very grateful :)

2
Jack404
Re: XoopsMultiMailer Problem!
  • 2004/5/8 22:16

  • Jack404

  • Just popping in

  • Posts: 56

  • Since: 2003/5/16


[bump]
PING? PONG!
[/bump]

3
Mithrandir
Re: XoopsMultiMailer Problem!

le="color: #000000"><?php $result = $xoopsDB->query($sql); $email = $result;

As far as I can see, you are giving the emails array the value of a resultset.
Instead do this:
le="color: #000000"><?php $result = $xoopsDB->query($sql); $email = array(); while ($thisemail = $xoopsDB->fetchArray($result)) { $email[] = $thisemail['email']; }


NOT TESTED - but should to the best of my knowledge work

4
Jack404
Re: XoopsMultiMailer Problem!
  • 2004/5/8 22:54

  • Jack404

  • Just popping in

  • Posts: 56

  • Since: 2003/5/16


Dang, I thought that would work too.

The error message now reads "SMTP Error: The following recipients failed [Array]"

At least it's not Resource id #26 anymore ;)

EDIT: Turning on PHP Debug showed this:

Notice: Array to string conversion in i:\ajxdesigns\class\mail\phpmailer\class.phpmailer.php on line 370

5
tl
Re: XoopsMultiMailer Problem!
  • 2004/5/8 22:58

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


Try to turn MySQL/Block debug on to see if the query statement is right. You got three types of quotes: ' ` "

Quote:
$sql = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0"


6
Jack404
Re: XoopsMultiMailer Problem!
  • 2004/5/8 23:00

  • Jack404

  • Just popping in

  • Posts: 56

  • Since: 2003/5/16


Yup, query was fine... funny how mySQL works :)

I just figured out what's wrong... I used the list() php function to get the array to change to a list, and now it works perfectly :)

7
Jack404
Re: XoopsMultiMailer Problem!
  • 2004/5/9 0:04

  • Jack404

  • Just popping in

  • Posts: 56

  • Since: 2003/5/16


I've got another problem...

le="color: #000000"><?php $sql[1] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 1,45'; $sql[2] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 46,90'; $sql[3] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 91,135'; $sql[4] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 136,180'; $sql[5] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 181,225'; $sql[6] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 226,270'; $sql[7] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 271,315'; $sql[8] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 316,360'; $sql[9] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 361,405'; $sql[10] = 'SELECT `email` FROM '.$xoopsDB->prefix('users').' WHERE `level` != "0" AND `rank` != "7" AND `rank` !="13" AND `rank` !="14" LIMIT 406,450'; $email[1] = array(); $email[2] = array(); $email[3] = array(); $email[4] = array(); $email[5] = array(); $email[6] = array(); $email[7] = array(); $email[8] = array(); $email[9] = array(); $email[10] = array(); $result[1] = $xoopsDB->query($sql[1]); $result[2] = $xoopsDB->query($sql[2]); $result[3] = $xoopsDB->query($sql[3]); $result[4] = $xoopsDB->query($sql[4]); $result[5] = $xoopsDB->query($sql[5]); $result[6] = $xoopsDB->query($sql[6]); $result[7] = $xoopsDB->query($sql[7]); $result[8] = $xoopsDB->query($sql[8]); $result[9] = $xoopsDB->query($sql[9]); $result[10] = $xoopsDB->query($sql[10]); while ($thisemail = $xoopsDB->fetchArray($result[1])) { $email[1][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[2])) { $email[2][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[3])) { $email[3][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[4])) { $email[4][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[5])) { $email[5][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[6])) { $email[6][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[7])) { $email[7][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[8])) { $email[8][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[9])) { $email[9][] = $thisemail['email']; } while ($thisemail = $xoopsDB->fetchArray($result[10])) { $email[10][] = $thisemail['email']; } list($emails[1]) = $email[1]; list($emails[2]) = $email[2]; list($emails[3]) = $email[3]; list($emails[4]) = $email[4]; list($emails[5]) = $email[5]; list($emails[6]) = $email[6]; list($emails[7]) = $email[7]; list($emails[8]) = $email[8]; list($emails[9]) = $email[9]; list($emails[10]) = $email[10];


I have 450 users I need to mail with my script, so I want to break it down. The code I pasted above does the trick, but is there a way to break it down using PHP or some other XOOPS function?

I know this isn't a forum for PHP, but I'm not sure how to use for() or while() statements in the code :/

Login

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits