[contrib] PHP function to add users / subscribe to lists

3rd party code for phpList

Re: SendMessage method

Postby shiny » 12:26am, Sat 31 Dec, 2011

I really dunno if someone made it before me and I dunno if this is the best way to schedule a message but I need it so feel free to modify it. Happy coding.
Code: Select all
    * scheduleMessage(subject, message, lists [, from, sendformat, template, ownerId])
    * @param subject
    *       The message subject
    * @param message
    *       The message boby
    * @param lists
    *       An array of lists which you want to send the message
    * @param from
    *       Optional, the from address
    * @param sendformat
    *       Optional, the default is the HTML format
    * @param template
    *       Optional, the template id you want to use
    * @param ownerId
    *       Optional, the admin id who is the owner of the message
    * @return boolean
    *       A boolean indicating success (TRUE) or failure (FALSE)
   public function scheduleMessage($subject, $message, $lists, $from = "site ur@site.com", $sendformat = "HTML", $template = "0", $ownerId ="5"){
      $from = $this->db->quote($from, 'text');
      $subject = $this->db->quote($subject, 'text');
      $message = $this->db->quote($message, 'text');
      $sendformat = $this->db->quote($sendformat, 'text');
        $template = $this->db->quote($template,'integer') ;
        $footer = $this->db->quote(
        '<p style="text-align:center"> | <a href="[PREFERENCESURL]">preferenze</a> | <a href="[UNSUBSCRIBEURL]">cancellati</a> | <a href="">privacy</a> | [USERTRACK]</p>',
      $ownerId = $this->db->quote($ownerId, 'integer');
      // Add the message into the message table
        $sql  = "INSERT INTO ".$this->tablePrefix."message (subject, fromfield, message, footer, entered, status, htmlformatted, sendformat, template, owner, embargo, repeatinterval, repeatuntil) ";
        $sql .= "VALUES ($subject, $from, $message, $footer, NOW(), 'submitted', '1', $sendformat, $template, $ownerId, NOW(), '0', NOW() )";
      $result =& $this->db->query($sql);
      if (MDB2::isError($result)) return $this->logError($result->getMessage());
      // Link the message to the lists which we want to send it
      $messageid = $this->db->lastInsertID();
        foreach ($lists as $list) {
           if (is_numeric($list)) $listId = $list;
          else $listId = $this->listName2listId($list);
          if (empty($listId)) return FALSE;
           $sql  = "INSERT INTO ".$this->tablePrefix."listmessage (messageid, listid, entered) ";
         $sql .= "VALUES ('$messageid', '$listId', NOW())";
         $result =& $this->db->query($sql);
         if (MDB2::isError($result)) return $this->logError($result->getMessage());
      return TRUE;
phpList newbie
Posts: 1
Joined: 12:14am, Sat 31 Dec, 2011

Re: [contrib] PHP function to add users / subscribe to lists

Postby joeyvmason » 7:50am, Mon 08 Oct, 2012

Is there any way this can be consolidated somehow into a real API for phplist?
Posts: 7
Joined: 11:49pm, Mon 26 Sep, 2011


Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 1 guest