Jump to content

I haven't a clue .... do any of you?


dazza37

Recommended Posts

I have a newsletter module built into the ecommerce software I'm using and need a bit of a mod. Currently, when a customer puts in their email address it emails them requesting confirmation and then a subsequent email with confirmation. I would like to bypass the request and just send them one email with a confirm/thank-you.

 

I've seemed to come down with the Mr. Bush syndrome all morning... endless cut n' past - trial n' error kinda thing! But I'm willing to step down!!

 

Any help would be appreciated!

 

Thanks,

Daz

 

<?php

/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */

func_define("SUBSCRIBER_EXISTS", 1);
func_define("SUBSCRIBE_SUCCESS", 0);
func_define("SUBSCRIBE_FAILED", -1);

/**
* New list subscriber description.
*
* @package Module_Newsletters
* @access public
* @version $Id: NewsSubscriber.php,v 1.8 2007/03/20 15:00:16 sheriff Exp $
*/
class NewsSubscriber extends Base
{
    var $fields = array(
            "list_id"  => 0,
            "email" => "",
            "since_date"  => 0,
            );

    var $primaryKey = array("list_id", "email");
    var $alias = "news_subscribers";
    var $defaultOrder = "since_date,email";

    function subscribe($email, $list_id, $verbose = true)
    {
        require_once "modules/Newsletters/encoded.php";
        if ($this->find("list_id=$list_id AND email='".addslashes(strtolower($email))."'")) {
            return SUBSCRIBER_EXISTS;
        }
        $this->set("email", strtolower($email));
        $this->set("list_id", $list_id);
        $this->set("since_date", time());
        $this->create();
        if ($verbose) {
            $params = array
            (
            	"email" => $this->get("email"),
                "list" => $this->getList(true),
                "code" => func_newsletters_gen_code($this->get("email"))
            );
            if (!is_null($this->get("profile"))) {
            	$params["profile"] = $this->get("profile");
            }
            $this->sendMail(
                    $this->get("email"),
                    "modules/Newsletters/subscribed",
                    $params
                    );
        }
        return SUBSCRIBE_SUCCESS;
    }

    function unsubscribe($email = null, $list_id = null, $verbose = true)
    {
        if (!is_null($email) && !is_null($list_id)) {
            if (!$this->find("list_id=$list_id AND email='".addslashes(strtolower($email))."'")) {
                return;
            }
        }
        $this->delete();
        if ($verbose) {
        	$this->set("list_id", $list_id);
            $params = array
            (
                "email" => $this->get("email"),
                "list" => $this->getList(true)
            );
            if (!is_null($this->get("profile"))) {
            	$params["profile"] = $this->get("profile");
            }
            $this->sendMail(
                    $this->get("email"),
                    "modules/Newsletters/unsubscribed",
                    $params
                    );
        }                
    }

    function request($email, $list_id = null)
    {
        $this->sendMail(
                $email,
                "modules/Newsletters/confirm_subscription",
                array("email" => $email,
                    "code" => func_newsletters_gen_code($email))
                );
    }

    function sendMail($email, $template, $params = array())
    {
        $mailer =& func_new("Mailer");
        if (!empty($params)) {
            foreach ($params as $param => $value) {
                $mailer->set($param, $value);
            }
        }
        $mailer->compose($this->get("config.Company.site_administrator"),
                         $email,
                         $template);
        $mailer->send();                         
    }

    function import($list_id, $fname)
    {
        if (($subscribers = file($fname)) === false) {
            die("failed to open CSV file $fname");
        }
        foreach ($subscribers as $num => $email) {
            trim($email);
            $email = preg_replace("/[\n\r\t]/", "", $email);
            echo "<b>Importing CSV line #$num...</b><br>";
            $num++;
            if (strlen($email) > 0) {
                $ns =& func_new("NewsSubscriber");
                $res = $ns->subscribe($email, $list_id);
                if ($res == SUBSCRIBER_EXISTS) {
                    echo "<font color=blue>Subscriber $email already exists!</font><br>";
                }
            } else {
			echo "<font color=red>Subscriber e-mail is wrong!</font><br>";
            }
        }
    }

    function &getList($as_new=false)
    {
    	if ($as_new) {
    		$this->list = null;
    	}
        if (is_null($this->list)) {
            $this->list =& func_new("NewsList", $this->get("list_id"));
        }
        return $this->list;
    }
} 

// WARNING:
// Please ensure that you have no whitespaces / empty lines below this message.
// Adding a whitespace or an empty line below this line will cause a PHP error.
?>

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.