I use Mandrill (now called Mailchimp Transactional) for order updates etc which I find more reliable delivery wise than sendmail. I don't use Mailchimp for newsletters through Phoenix Cart Admin.
It wasn't too difficult, just added a simple mailchimp connector
Code: Select all
<?php
class MailchimpTransactional {
private $api_key;
private $api_url = 'https://mandrillapp.com/api/1.0/messages/send.json';
public function __construct() {
if (!defined('MODULE_HEADER_TAGS_MAILCHIMP_TRANSACTIONAL_API_KEY')) {
throw new Exception('MODULE_HEADER_TAGS_MAILCHIMP_TRANSACTIONAL_API_KEY is not defined.');
}
$this->api_key = MODULE_HEADER_TAGS_MAILCHIMP_TRANSACTIONAL_API_KEY;
}
public function sendEmail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address, $attachments = []) {
$postData = [
'key' => $this->api_key,
'message' => [
'from_email' => $from_email_address,
'from_name' => $from_email_name,
'subject' => $email_subject,
'html' => $email_text,
'to' => [
[
'email' => $to_email_address,
'name' => $to_name,
'type' => 'to'
]
]
]
];
if (!empty($attachments)) {
foreach ($attachments as $attachment) {
$postData['message']['attachments'][] = $attachment;
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->api_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
$responseArray = json_decode($response, true);
if (isset($responseArray[0]['status']) && $responseArray[0]['status'] === 'sent') {
return ['success' => true, 'message' => 'Email sent successfully.'];
} else {
return ['success' => false, 'message' => 'Error sending email: ' . json_encode($responseArray)];
}
} else {
return ['success' => false, 'message' => 'HTTP Error: ' . $httpCode . ' - ' . $response];
}
}
}
and created new notification modules, for example:
Code: Select all
<?php
/*
Mailchimp Transactional for Phoenix Cart
Copyright (c) 2025 F. Ludriks
Released under the GNU General Public License
*/
class n_password_forgotten_mailchimp extends abstract_module {
const CONFIG_KEY_BASE = 'MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_';
const TRIGGERS = [ 'password_forgotten' ];
const REQUIRES = [ 'email_address' ];
public function notify($data) {
$mailer = new MailchimpTransactional;
ob_start();
include Guarantor::ensure_global('Template')->map(__FILE__);
echo $GLOBALS['hooks']->cat('passwordForgottenNotification');
$response = $mailer->sendEmail($data['name'], $data['email'], sprintf(MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_SUBJECT, STORE_NAME), ob_get_clean(), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
return json_encode($response);
}
protected function get_parameters() {
return [
static::CONFIG_KEY_BASE . 'STATUS' => [
'title' => 'Enable Password Forgotten Notification module',
'value' => 'True',
'desc' => 'Do you want to add the module to your shop?',
'set_func' => "Config::select_one(['True', 'False'], ",
],
];
}
}
Plus a template and language file for each of course
Code: Select all
<?php
$output = '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Forgotten - ' . STORE_NAME . '</title>
</head>
<body style="margin: 0; padding: 0; background-color: #f4f4f4;">
<table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#f4f4f4">
<tr>
<td align="center">
<table width="600" cellspacing="0" cellpadding="20" border="0" bgcolor="#ffffff" style="border-radius: 10px; box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);">
<!-- Logo -->
<tr>
<td align="center" style="padding: 20px;">
<img src="' . HTTP_SERVER . '/images/' . STORE_LOGO . '" width="200" style="display: block;" alt="' . STORE_NAME . ' Logo">
</td>
</tr>
<!-- Title & Description -->
<tr>
<td align="center" style="font-family: Arial, sans-serif; color: #333333; padding: 20px;">
<h1 style="margin: 0; font-size: 24px;">'
. sprintf(MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_TITLE, $data['name']) .
'</h1>
<p style="margin: 15px 0 25px 0; font-size: 16px; color: #555555;">'
. nl2br(sprintf(MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_RESET_BODY, '')) .
'</p>
<!-- Reset Password Button -->
<table cellspacing="0" cellpadding="0" border="0" align="center">
<tr>
<td align="center" bgcolor="#198754" style="border-radius: 6px;">
<a href="' . htmlspecialchars($data['reset_url'], ENT_QUOTES, 'UTF-8') . '"
target="_blank"
style="display:inline-block;padding:14px 28px;font-size:16px;font-family:Arial,sans-serif;color:#ffffff;text-decoration:none;font-weight:bold;border-radius:6px;">
Reset Your Password
</a>
</td>
</tr>
</table>
<p style="margin-top: 15px; font-size: 13px; color: #999999;">
Or copy and paste this link into your browser:<br>
<a href="' . htmlspecialchars($data['reset_url'], ENT_QUOTES, 'UTF-8') . '"
style="color:#007bff; word-break: break-all;">'
. htmlspecialchars($data['reset_url'], ENT_QUOTES, 'UTF-8') .
'</a>
</p>
<p style="margin-top: 25px; font-size: 14px; color: #777777;">
This link will expire after 24 hours or once your password has been changed.
</p>
<p style="margin-top: 25px; font-size: 14px; color: #777777;">
' . MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_IGNORE . '
</p>
</td>
</tr>
<!-- Contact & Footer -->
<tr>
<td align="center" style="font-family: Arial, sans-serif; color: #555555; font-size: 14px;">
<p>If you have any questions, please reply to this email.</p>
<p>' . STORE_NAME . ' • ABN: ' . STORE_TAX_ID . ' • ' . STORE_ADDRESS . ' • ' . STORE_PHONE . '</p>
<p><a href="' . HTTP_SERVER . '/contact_us.php" style="color: #007bff; text-decoration: none;">Need help? Contact Us</a></p>
</td>
</tr>
<tr>
<td align="center" bgcolor="#333333" style="font-family: Arial, sans-serif; color: #ffffff; font-size: 14px; padding: 10px; border-radius: 0 0 10px 10px;">
<p>Thank you for shopping with us!</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>';
echo $output;
Code: Select all
<?php
const MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_TEXT_TITLE = 'Password Forgotten for Mailchimp';
const MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_TEXT_DESCRIPTION = 'Send a notification when customer needs a password reset.';
const MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_SUBJECT = '%s - New Password';
const MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_TITLE = 'Hello %s' . "\n\n";
const MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_RESET_BODY = 'A new password has been requested for your profile at ' . STORE_NAME . '.' . "\n\n" . 'Please follow this personal link to securely change your password:' . "\n\n";
const MODULE_NOTIFICATIONS_PASSWORD_FORGOTTEN_MAILCHIMP_IGNORE = 'Please ignore if it wasn\'t you that requested to change your password.' . "\n\n";