Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send an email via MailChimp

Tags:

mailchimp

I think problem is around $api->listSubscribers()

include('../libs/mailchimp/MCAPI.class.php');

$options = array('list_id' => '$list_id', 'subject' => 'Prova', 'from_name' => 'name', 'from_email' => '[email protected]');
$content = array('html' => '<p>Testo di prova</p>');

$api = new MCAPI($apikey);
$campaignId = $api->campaignCreate('trans', $options, $content);

$api->listSubscribe($options['list_id']);

$api->campaignSendNow($campaignId);

if ($api->errorCode){
    echo "Unable to Create New Campaign!";
    echo "\n\tCode=".$api->errorCode;
    echo "\n\tMsg=".$api->errorMessage."\n";
} else {
    echo "New Campaign ID:".$campaignId ."\n";
}

Why does'nt it send an email?

like image 436
Leonardo Avatar asked Dec 06 '25 04:12

Leonardo


1 Answers

You have a several issues here:

The first one is that you are not doing error checking after each API call. If you take the error checking code from the bottom and stick it after the listSubscribe() call, you'll immediately get an error because you aren't passing any sort of subscriber data (at the very least you need the email address). The docs for listSubscribe are here

Once you do that - unless you've thoroughly read and considered the options in the listSubscribe docs - your second issue is going to be that you are running listSubscribe with the double_optin parameter set to true (the default), which means they won't be subscribed until clicking a link in the confirmation email.

Next, that code is just going to get you in trouble, and probably quickly. If you are going to use psuedo-transcational campaigns it is imperrative that you only create ONE psuedo-trans campaign per type of email and then send that campaign over and over. That's how they are intended to work. Not doing that is going to cause you to fill up your account with a whole bunch of trash campaigns at which point there's no point in using a psuedo-trans campaign since that's the same as creating/sending a regular campaign to a single user over and over.

like image 110
jesse Avatar answered Dec 12 '25 15:12

jesse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!