代码点火器和邮戳集成


CodeIgniter and Postmark Integration

我对编码点火器和邮戳很陌生,有没有办法将两者集成?

我创建了一个名为 cron.php 的控制器,并将邮戳代码放在方法入站中,这是我的代码:

public function inbound()
{   
  try {
        require_once '../lib/Postmark/Autoloader.php';
        'Postmark'Autoloader::register();
        // this file should be the target of the callback you set in your postmark account
        $inbound = new 'Postmark'Inbound(file_get_contents('php://input'));

        $this->data['client'] = $this->client_model->get_where($m_where);
        if(!empty($this->data['client']))
        {
            $m_insert = array('cme_username' => $inbound->FromName(), 
                              'cme_title' => $inbound->Subject(),
                              'cme_message' => $inbound->TextBody(),
                              'cme_client' => $this->data['client']['ccl_id'],
                              'cme_from' => 'client',
                              'cme_through' => 'email',
                              'cme_date_sent' => date('Y-m-d H:i:s'),
                              'cme_admin' => 0);
            $this->message_model->insert($m_insert);
        }
    }
    catch (Exception $e) {
        echo $e->getMessage();
    }}

我也想知道我做得是否正确?非常感谢!

您只需从应用程序/库/目录中的 PostMarkApp.com 网站中提取一个示例类(我使用了这个并将其重命名为postmark),并像任何其他 CI 库一样使用它。 确保你定义了正确的全局变量(我在application/config/config.php中定义了它们)。

应用程序/配置

/配置.php

define('POSTMARKAPP_API_KEY', 'YOUR-POSTMARKAPP-API-KEY');    
define('POSTMARKAPP_MAIL_FROM_ADDRESS', 'you@yourdomain.com');
应用程序/控制器

/某些控制器.php

class somecontroller extends CI_Controller { 
  function someControllerMethod(){

    $this->load->library('postmark');
    $this->postmark->addTo('someone@somewhere.com', 'John Doe')
                  ->subject('My email subject')
                  ->messagePlain('Here is a new message to John!')
                  ->tag('some-tag')
                  ->send();
  }
}

希望对您有所帮助!