Add customers to Magento newsletter via web form form

Recently I was tasked with adding customers to a Magento newsletter via a pre-exisitng form. Previously this form just sent an email that was mostly ignored, so now the ManInCharge wanted it feeding into Magento, which has several nice plugins for MailChimp integration, but that’s a story for another day.

Setup your form just like any other HTML text form, point it with a POST action at something like this:

$email = $_POST["email"];
if ($email){

# create new subscriber without send an confirmation email
Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);

# get just generated subscriber
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);

# change status to "subscribed" and save
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
$subscriber->save();
}

With some help from ifuelinteractive and paniticz

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>