Skip to content

Commit

Permalink
Fixed Newsletters 'view' and 'edit' actions. You can now send test em…
Browse files Browse the repository at this point in the history
…ails of the newsletter from the view action.
  • Loading branch information
BigHeadCreations committed Aug 30, 2012
1 parent 2e879b7 commit b46842d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 13 deletions.
1 change: 1 addition & 0 deletions Config/bootstrap.php
Expand Up @@ -36,6 +36,7 @@
App::uses('AppModel', 'Model');
App::uses('AppController', 'Controller');
App::uses('AppHelper', 'View/Helper');
App::uses('InfinitasEmail', 'Core/Emails/Network/Email');

App::uses('ClearCache', 'Data.Lib');
App::uses('EventCore', 'Events.Lib');
Expand Down
53 changes: 53 additions & 0 deletions Config/email.php
@@ -0,0 +1,53 @@
<?php
/**
* This is email configuration file.
*
* Use it to configure email transports of Cake.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package app.Config
* @since CakePHP(tm) v 2.0.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* In this file you set up your send email details.
*
* @package cake.config
*/
/**
* Email configuration class.
* You can specify multiple configurations for production, development and testing.
*
* transport => The name of a supported transport; valid options are as follows:
* Mail - Send using PHP mail function
* Smtp - Send using SMTP
* Debug - Do not send the email, just return the result
*
* You can add custom transports (or override existing transports) by adding the
* appropriate file to app/Network/Email. Transports should be named 'YourTransport.php',
* where 'Your' is the name of the transport.
*
* from =>
* The origin email. See CakeEmail::from() about the valid values
*
*/
class EmailConfig {

public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'infinitastest@gmail.com',
'password' => 'testtesttest',
'transport' => 'Smtp'
);

}
Expand Up @@ -162,6 +162,7 @@ public function actionAdminEdit($id = null, $query = array()) {
$query['conditions'][$this->Controller->{$this->Controller->modelClass}->alias . '.' . $this->Controller->{$this->Controller->modelClass}->primaryKey] = $id;

$this->Controller->request->data = $this->Controller->{$this->Controller->modelClass}->find('first', $query);

if(empty($this->Controller->request->data)) {
$this->Controller->notice('invalid');
}
Expand Down
45 changes: 33 additions & 12 deletions Core/Newsletter/Controller/NewslettersController.php
Expand Up @@ -244,6 +244,22 @@ public function admin_index() {
}

public function admin_add() {
if ($this->request->isPost()) {
$campaignId = $this->request->data['Newsletter']['campaign_id'];

$campaign = $this->Newsletter->Campaign->find('first', array(
'fields' => array(
'template_id'
),
'conditions' => array(
'Campaign.id' => $campaignId
)
)
);

$this->request->data['Newsletter']['template_id'] = $campaign['Campaign']['template_id'];
}

parent::admin_add();

$campaigns = $this->Newsletter->Campaign->find('list');
Expand All @@ -268,6 +284,8 @@ public function admin_view($id = null) {
}

$newsletter = $this->Newsletter->read(null, $id);
$templateId = $newsletter['Newsletter']['template_id'];
$template = $this->Newsletter->Template->read(null, $templateId);

if (!empty($this->request->data)) {
$id = $this->request->data['Newsletter']['id'];
Expand All @@ -282,24 +300,20 @@ public function admin_view($id = null) {
)
);
}

$sent = 0;
foreach($addresses as $address) {
$this->Email->from = 'Infinitas Test Mail <' . $newsletter['Newsletter']['from'] . '>';
$this->Email->to = 'Test <' . $address . '>';
$email = new InfinitasEmail('gmail');
$email->from(array($newsletter['Newsletter']['from'] => 'Infinitas'));
$email->to($address);

$this->Email->subject = strip_tags($newsletter['Newsletter']['subject']);
$this->set('email', $newsletter['Template']['header'] . $newsletter['Newsletter']['html'] . $newsletter['Template']['footer']);
$email->subject(strip_tags($newsletter['Newsletter']['subject']));

if ($this->Email->send()) {
if ($email->send($template['Template']['header'] . $newsletter['Newsletter']['html'] . $template['Template']['footer'])) {
$sent++;
}

pr($this->Email->smtpError);

$this->Email->reset();
}

}

$this->notice(sprintf(__('%s mails were sent'), $sent));
}

Expand All @@ -310,6 +324,12 @@ public function admin_view($id = null) {
$this->set('newsletter', $this->Newsletter->read(null, $id));
}

public function admin_edit($id = null) {
parent::admin_edit();

$this->set('campaigns', $this->Newsletter->Campaign->find('list'));
}

public function admin_preview($id = null) {
$this->layout = 'ajax';

Expand Down Expand Up @@ -338,6 +358,7 @@ public function admin_preview($id = null) {
);

$this->set('data', $newsletter['Template']['header'] . $newsletter['Newsletter']['html'] . $newsletter['Template']['footer']);
Configure::write('debug', 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Newsletter/View/Newsletters/admin_view.ctp
Expand Up @@ -27,7 +27,7 @@
<h3><?php echo __('Test in a mail client'); ?></h3>
<?php
echo $this->Form->create('Newsletter', array('action' => 'view'));
echo '<p>', __('Enter the email addresses you would like to send to seperated by a , {comma}.'), '</p>';
echo '<p>', __('Enter the email addresses you would like to send to seperated by a , {comma} (but with no spaces)'), '</p>';
echo $this->Form->input('id', array('value' => $this->data['Newsletter']['id']));
echo $this->Form->input('email_addresses', array('type' => 'textarea', 'class' => 'title'));
echo $this->Form->end('Send the test');
Expand Down

0 comments on commit b46842d

Please sign in to comment.