I’ve had a chance to make a couple of improvements to my SMTP Pro email extension for Magento. Both changes are not exactly life altering, one adds extra error detection to the self-test, and the other fixes a header problem with the self-test (reported by Phil). More details follow about the changes, if you want to get the extension, download SMTP Pro on Magento Connect. (Updated: finally on Magento Connect!)
I now send a real live contact form message as part of the testing – and ensure that when the email sends, my extension code is actually being called. I’ve had a lot of people reporting problems with emails not sending lately, only to find it’s because some other extension is interfering with my email sending. This tweak to the self test will help identify those issues.
This is implemented as a static variable on the self test controller, that is set before sending the test email and then altered by the email observer (if it is called as expected):
// Now we test that the actual core overrides are occuring as expected.
// We trigger the password forgot email, as though a user had done so.
self::$CONTACTFORM_SENT = false;
$this->_sendTestContactFormEmail();
// If everything worked as expected, the observer will have set this value to true.
if (self::$CONTACTFORM_SENT) {
$msg = $msg . "<br/> Contact Form test email used SMTPPro to send correctly.";
} else {
$success = false;
$msg = $msg . "<br/> Contact Form test email did not use SMTPPro to send.";
} |
// Now we test that the actual core overrides are occuring as expected.
// We trigger the password forgot email, as though a user had done so.
self::$CONTACTFORM_SENT = false;
$this->_sendTestContactFormEmail();
// If everything worked as expected, the observer will have set this value to true.
if (self::$CONTACTFORM_SENT) {
$msg = $msg . "<br/> Contact Form test email used SMTPPro to send correctly.";
} else {
$success = false;
$msg = $msg . "<br/> Contact Form test email did not use SMTPPro to send.";
}
and the code in the observer that alters this variable:
// For the self test, if we're sending the contact form notify the self test class
if($event->getTemplate() == "contacts_email_email_template") {
include_once "app/code/community/Aschroder/SMTPPro/controllers/IndexController.php";
Aschroder_SMTPPro_IndexController::$CONTACTFORM_SENT = true;
} |
// For the self test, if we're sending the contact form notify the self test class
if($event->getTemplate() == "contacts_email_email_template") {
include_once "app/code/community/Aschroder/SMTPPro/controllers/IndexController.php";
Aschroder_SMTPPro_IndexController::$CONTACTFORM_SENT = true;
}
The other change was trivial, adding a ->setFrom()
call when sending the test email. Thanks to Phil for pointing that out.
Lastly, Eric requested a useful feature which I will add, but I haven’t had time to put that in to this release, next time!
Let me know any feedback you have on the changes, or if you’re having trouble sending emails in Magento – feedback welcome.