首页 > 解决方案 > Magento 如何在外部 php 文件中包含 zend 邮件库

问题描述

我在 var 目录中创建了一个单独的 php 文件,用于 cron 作业。我添加了 zend 邮件功能,但它不工作也没有给出任何错误。

ini_set('display_errors', 1);
error_reporting(E_ALL);

    require_once('app/Mage.php'); //Path to Magento
    require_once('lib/Zend/Mail.php');
    require_once('lib/Zend/Mail/Transport/Smtp.php'); 
    umask(0);
    Mage::app();

        $mail = new Zend_Mail();
                     $mail->addTo('mymail@mail.com','apple');
                    $mail->setFrom('sender@mail.com','sender');
                  $mail->setSubject('notifications');
                    $mail->setBodyHTML('<p>hi</p>','UTF-8');  // your content or message

                try {
                    $mail->send();
                    echo "mail sent";

                }
                catch (Exception $e) {
                    print_r($e);

                }

标签: phpmagentozend-frameworkmagento-1.9

解决方案


我假设您的 var 目录是公开的,添加自动加载路径

require getcwd() . '/../vendor/autoload.php'; // configure autoload path as per your file location.

ini_set('display_errors', 1);
error_reporting(E_ALL);

require_once('app/Mage.php'); //Path to Magento, may be this not required.  
umask(0);
Mage::app();

    $mail = new Zend_Mail();
                 $mail->addTo('mymail@mail.com','apple');
                $mail->setFrom('sender@mail.com','sender');
              $mail->setSubject('notifications');
                $mail->setBodyHTML('<p>hi</p>','UTF-8');  // your content or message

            try {
                $mail->send();
                echo "mail sent";

            }
            catch (Exception $e) {
                print_r($e);

            }

推荐阅读