Mailchimp API (PHP) - Your Campaign is not ready to send - php

I am having a problem usign the Mailchimp API with PHP.
When I'm running the code, this is the error I get:
{
"type": "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
"title": "Bad Request",
"status": 400,
"detail": "Your Campaign is not ready to send.",
"instance": "46235d29-6a67-4d55-800d-a95e2dc7273f"
}
I know why the campaign is not ready to send, as you can see in this image, the details are filled, but not saved:
Here is the code I'm trying to run:
<?php
require '../vendor/autoload.php';
$apiKey = 'API ';
$mailchimp = new \MailchimpAPI\Mailchimp($apiKey);
$list_created = $mailchimp->lists()->post([
'name' => 'Lista Monday',
'contact' => [
'company' => 'Test Company Monday',
'address1' => 'Monday address 1',
'city' => 'Monday City',
'state' => 'Monday State',
'zip' => '227560',
'country' => 'Romania'
],
'permission_reminder' => 'test',
'campaign_defaults' => [
'from_name' => 'Anjus Parsay',
'from_email' => 'FROM EMAIL',
'subject' => 'Monday Email',
'language' => 'English'
],
'email_type_option' => false
]);
$list_id = json_decode($list_created->getBody(), true)['id'];
$email = "EMAIL ";
$addedUser = $mailchimp->lists($list_id)->members()->post([
'email_address' => $email,
'status' => 'subscribed'
]);
//1. Create the template
$template_content = file_get_contents("http://widevisiondesign.com/anjus/mailchimp/src/testTemplate.html");
$template = $mailchimp->templates()->post([
'name' => 'testTemplateHTML',
'html' => $template_content
]);
$template_id = json_decode($template->getBody(), true)['id'];
//2. Create a campaign
$campaign = $mailchimp->campaigns()->post([
'type' => 'regular',
'recipients' => [
'list_id' => $list_id
],
'settings' => [
'title' => 'Monday',
'subject_line' => 'Monday - Sunday',
'from_name' => 'NAME NAME',
'to_name' => 'test',
'preview_text' => 'Preview text - Monday',
'template_id' => $template_id
]
]);
$campaign_id = json_decode($campaign->getBody(), true)['id'];
$sent = $mailchimp->campaigns($campaign_id)->send([$email], 'plaintext')->getBody();
print_r($sent);
?>
Thank you!

From the code and screenshot you presented, here are some things that came to my mind:
Have you verified and authenticated your email address? If no, you need to authenticate the domain of your email address. Go to your Mailchimp dashboard, click Account > Settings > Domains > Verify a Domain.
Then add your domain, follow the instruction to verify and authenticate.
If you prefer, you can make an API call to get a checklist before actually sending the email. The checklist gives a success and error notes on what needs to be done before actually sending the email.
I'm sorry if this seems somehow but did you really provide your email address in place of the 'FROM EMAIL' placeholder? From the code, it seems that you set the name of the from_name but did not set the from_email.

Related

Creating new address on shippo gives 500 error

I am creating a new address using shippo api using test token and when i give the array of address and click create it gives me 500 error. I am doing everything according to the docs given by shippo here is my code that I am using. The request I am sending is through ajax.
require_once ABSPATH . '/shippo/shippo/lib/Shippo';
Shippo::setApiKey("test_token");
$address = Shippo_Address::
create(
array(
'object_purpose' => 'QUOTE',
'name' => 'John Smith',
'company' => 'Initech',
'street1' => '6512 Greene Rd.',
'city' => 'Woodridge',
'state' => 'IL',
'zip' => '60517',
'country' => 'US',
'phone' => '773 353 2345',
'email' => 'jmercouris#iit.com',
'metadata' => 'Customer ID 23424'
));
var_dump($address);
I am confuse that what is it that I am doing wrong or missing?

Mandrill not showing the right Cc information

This issue really driving me crazy this past hours. Why is the email that send with Mandrill not showing the right information about the Cc email address.
So for example, I want to send email to
receiver_to_a#mail.com
receiver_cc_a#mail.com
receiver_cc_b#mail.com
When I see the email header on receiver_cc_a#mail.com. its always show no cc, and that email is send "to" receiver_cc_a#mail.com, not as cc
Is anyone having the same problem? I already try sending email in PHP with PhpMailer and also try from the PHP API from Mandrill itself but no luck.
You need to set the option preserve_recipients to true.
$message = array(
'html' => '<p>Example HTML content</p>',
'text' => 'Example text content',
'subject' => 'example subject',
'from_email' => 'message.from_email#example.com',
'from_name' => 'Example Name',
'to' => array(
array(
'email' => 'recipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'to'
),
array(
'email' => 'ccrecipient.email#example.com',
'name' => 'Recipient Name',
'type' => 'cc'
)
),
'headers' => array('Reply-To' => 'message.reply#example.com'),
'preserve_recipients' => true
);

PHP reply-to error - comes up with random email not sender of contact form

I have a contact form set up on my website (done through Adobe Muse)
the email is set up to send to multiple address
One of those addresses has an auto confirmation bounce back email.
The From address is NOT the email entered in the form itself but the email associated to my Adobe I.D meaning I'm receiving ALL the bounce back emails and to others it looks like the forms are coming from a single email address not the people sending off the form on the website.
I've managed to track down the php code for the form itself but have very limited knowledge when it comes to coding.
How can I get the code to make the "from" address or the repyl-to address the same as the person filling out the forms
See below
<?php
/*
If you see this text in your browser, PHP is not configured correctly on this hosting provider.
Contact your hosting provider regarding PHP configuration for your site.
PHP file generated by Adobe Muse CC 2015.2.1.352
*/
require_once('form_process.php');
$form = array(
'subject' => 'SSUPPORT FOR EXTENSIONS TO AVOCA BEACH PICTURE THEATRE IN LAND & ENVIRONMENT COURT - DA42661/2012 Submission',
'heading' => 'New Form Submission',
'success_redirect' => '',
'resources' => array(
'checkbox_checked' => 'Selected',
'checkbox_unchecked' => 'Unselected',
'submitted_from' => 'Form submitted from website: %s',
'submitted_by' => 'Visitor IP address: %s',
'too_many_submissions' => 'Too many recent submissions from this IP',
'failed_to_send_email' => 'Failed to send email',
'invalid_reCAPTCHA_private_key' => 'Invalid reCAPTCHA private key.',
'invalid_field_type' => 'Unknown field type \'%s\'.',
'invalid_form_config' => 'Field \'%s\' has an invalid configuration.',
'unknown_method' => 'Unknown server request method'
),
'email' => array(
'from' => 'saveaseat#avocabeachpicturetheatre.com.au',
'to' => 'saveaseat#avocabeachpicturetheatre.com.au,ask#centralcoast.nsw.gov.au,Carolyn.Wesley#gosford.nsw.gov.au,Ariella.Whitelum#gosford.nsw.gov.au'
),
'fields' => array(
'custom_U262562' => array(
'order' => 1,
'type' => 'string',
'label' => 'Name',
'required' => true,
'errors' => array(
'required' => 'Field \'Name\' is required.'
)
),
'Email' => array(
'order' => 2,
'type' => 'email',
'label' => 'Email',
'required' => true,
'errors' => array(
'required' => 'Field \'Email\' is required.',
'format' => 'Field \'Email\' has an invalid email address.'
)
),
'custom_U262553' => array(
'order' => 4,
'type' => 'string',
'label' => 'Message',
'required' => false,
'errors' => array(
)
),
'custom_U262696' => array(
'order' => 3,
'type' => 'string',
'label' => 'Postcode',
'required' => false,
'errors' => array(
)
)
)
);
process_form($form);
?>
Or maybe if you add replay-to in email array, like:
'email' => array(
'from' => 'saveaseat#avocabeachpicturetheatre.com.au',
'to' => 'saveaseat#avocabeachpicturetheatre.com.au,ask#centralcoast.nsw.gov.au,Carolyn.Wesley#gosford.nsw.gov.au,Ariella.Whitelum#gosford.nsw.gov.au',
'replay-to' => 'Email for replay'
),

Sending email with Mandrill using PHP

I'm trying to send email using Mandrill and PHP and I can't get it to send.
I've downloaded the PHP API wrapper from here:https://packagist.org/packages/mandrill/mandrill
Mandrill.php is in my root and the Mandrill folder is in the same directory.
Here's my code:
<?php
require_once 'Mandrill.php';
$mandrill = new Mandrill('MY API KEY IS USUALLY HERE');
$message = array(
'subject' => 'Test message',
'from_email' => 'jwjody#yahoo.com',
'from_name' => 'Sender person',
'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>',
'to' => array(array('email' => 'jwjody#yahoo.com', 'name' => 'Recipient 1')),
'merge_vars' => array(array(
'rcpt' => 'recipient1#domain.com',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Recipient 1 first name'),
array(
'name' => 'LASTNAME',
'content' => 'Last name')
))));
//print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message));
echo ("hello");
?>
But it won't send. I'm not sure where the failure is. Is it something obvious I'm missing?
I see the issue now.
I see what's going on now!
I changed
$mandrill->messages->sendTemplate($template_name, $template_content, $message));
to
$mandrill->messages->send($message, $async=false, $ip_pool=null, $send_at=null);
And it works!
Instead of calling the sendTemplate() function I should have used
$mandrill->messages->send($message, $async=false, $ip_pool=null, $send_at=null);
Once I changed the function call the mail was sent.

Mandrill and PHP not sending transactional email out

So I've made a template called 'Basic' within Mandrill. I did a test send and it looks great. I put Mandrill into test mode and used the test API key in my code. I'm just trying to get the php to send out a test transactional email, but no email gets sent. Here is the printed response I get:
Array ( [0] => Array ( [email] => amiecrutchley02#gmail.com [status] => sent [_id] => 89bfab4c3938486eb9e36564f79a3e9f [reject_reason] => ) )
So I'm really not sure why I'm not receiving anything.
Here is my code:
<?php
require_once('includes/mandrill/Mandrill.php');
$mandrill = new Mandrill('my_api_key');
$message = array(
'subject' => 'Thank You For Your Purchase',
'from_email' => 'no-reply#acq.com',
'from_name' => 'ACQ',
'to' => array(array('email' => 'amiecrutchley02#gmail.com', 'name' => 'Amie')),
'merge_vars' => array(array(
'rcpt' => 'amiecrutchley02#gmail.com',
'vars' =>
array(
array(
'name' => 'FIRSTNAME',
'content' => 'Amie'),
array(
'name' => 'LASTNAME',
'content' => 'Crutchley')
))));
$template_name = 'Basic';
$template_content = array(
array(
'name' => 'main',
'content' => 'Hi *|FIRSTNAME|* *|LASTNAME|*, your profile has been updated!'),
array(
'name' => 'footer',
'content' => 'ACQ, Copyright 2014')
);
$response = $mandrill->messages->sendTemplate($template_name, $template_content, $message);
print_r($response);
?>
a test API key is specifically designed to not send email. It's designed so you can mimic sending email, but doesn't actually send. You're also not charged for sending tests. Here's the Mandrill KB about what test mode is, and how it works: Does Mandrill have a test mode or sandbox?
Well, weird, but my test API was the problem. I tried the public API and boom! It works!

Categories