【问题标题】:Magento how to include zend mail library in external php fileMagento 如何在外部 php 文件中包含 zend 邮件库
【发布时间】:2019-03-01 18:25:15
【问题描述】:

我在 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);

                }

【问题讨论】:

    标签: php magento zend-framework magento-1.9


    【解决方案1】:

    我假设你的 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);
    
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 2023-03-16
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      相关资源
      最近更新 更多