Meta 13 Project Blog
  • Home
  • Links
  • CMS
  • CSS
  • Ecom
  • Email
  • Flash
  • Google
  • HTML
  • Javascript
  • OS
  • PHP
  • SEO
  • SQL
Browse: Home / c5

c5

Add Attachments to C5 Forms

By Paul on July 29, 2013

If you have a file input field on a C5 form and you want it to send those files in the notify email

First open concrete/helpers/mail.php it should look like this

defined('C5_EXECUTE') or die("Access Denied.");
class MailHelper extends Concrete5_Helper_Mail {
}

Make it look like this

defined('C5_EXECUTE') or die("Access Denied.");
class MailHelper extends Concrete5_Helper_Mail {
    protected $files = array();
    
    /**
     * Add an attachement to the email by the file id
     * @param int $fileId
     */
    public function AddAttachmentById($fileId) {
        Loader::model('file');
        $this->files[] = File::getByID($fileId);
    }
    
    /**
     * Add an attachment to the email
     * @param File $file
     */
    public function addAttachment($file) {
        $this->files[] = $file;
    }
    
    /** 
    * Sends the email
    * @return void
    */
    public function sendMail($resetData = true) {
        $_from[] = $this->from;
        $fromStr = $this->generateEmailStrings($_from);
        $toStr = $this->generateEmailStrings($this->to);
        $replyStr = $this->generateEmailStrings($this->replyto);
        if (ENABLE_EMAILS) {

            $zendMailData = self::getMailerObject();
            $mail=$zendMailData['mail'];
            $transport=(isset($zendMailData['transport']))?$zendMailData['transport']:NULL;

            if (is_array($this->from) && count($this->from)) {
                if ($this->from[0] != '') {
                    $from = $this->from;
                }
            }
            if (!isset($from)) {
                $from = array(EMAIL_DEFAULT_FROM_ADDRESS, EMAIL_DEFAULT_FROM_NAME);
                $fromStr = EMAIL_DEFAULT_FROM_ADDRESS;
            }

            // The currently included Zend library has a bug in setReplyTo that
            // adds the Reply-To address as a recipient of the email. We must
            // set the Reply-To before any header with addresses and then clear
            // all recipients so that a copy is not sent to the Reply-To address.
            if(is_array($this->replyto)) {
                foreach ($this->replyto as $reply) {
                    $mail->setReplyTo($reply[0], $reply[1]);
                }
            }
            $mail->clearRecipients();


            $mail->setFrom($from[0], $from[1]);
            $mail->setSubject($this->subject);
            foreach($this->to as $to) {
                $mail->addTo($to[0], $to[1]);
            }

            if(is_array($this->cc) && count($this->cc)) {
                foreach($this->cc as $cc) {
                    $mail->addCc($cc[0], $cc[1]);
                }
            }

            if(is_array($this->bcc) && count($this->bcc)) {
                foreach($this->bcc as $bcc) {
                    $mail->addBcc($bcc[0], $bcc[1]);
                }
            }

            $mail->setBodyText($this->body);
            if ($this->bodyHTML != false) {
                $mail->setBodyHTML($this->bodyHTML);
            }
            
            if (!empty($this->files)) {
                Loader::library('3rdparty/Zend/Mime/Part');
                Loader::library('3rdparty/Zend/Mime');
                foreach ($this->files as $file) {
                    $part = new Zend_Mime_Part(file_get_contents($file->getPath()));
                    $part->filename = basename($file->getPath());
                    $part->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
                    $part->encoding = Zend_Mime::ENCODING_BASE64;
                    $mail->addAttachment($part);
                }
            }
            
            try {
                $mail->send($transport);

            } catch(Exception $e) {
                $l = new Log(LOG_TYPE_EXCEPTIONS, true, true);
                $l->write(t('Mail Exception Occurred. Unable to send mail: ') . $e->getMessage());
                $l->write($e->getTraceAsString());
                if (ENABLE_LOG_EMAILS) {
                    $l->write(t('Template Used') . ': ' . $this->template);
                    $l->write(t('To') . ': ' . $toStr);
                    $l->write(t('From') . ': ' . $fromStr);
                    if (isset($this->replyto)) {
                        $l->write(t('Reply-To') . ': ' . $replyStr);
                    }
                    $l->write(t('Subject') . ': ' . $this->subject);
                    $l->write(t('Body') . ': ' . $this->body);
                }				
                $l->close();
            }
        }

        // add email to log
        if (ENABLE_LOG_EMAILS) {
            $l = new Log(LOG_TYPE_EMAILS, true, true);
            if (ENABLE_EMAILS) {
                $l->write('**' . t('EMAILS ARE ENABLED. THIS EMAIL WAS SENT TO mail()') . '**');
            } else {
                $l->write('**' . t('EMAILS ARE DISABLED. THIS EMAIL WAS LOGGED BUT NOT SENT') . '**');
            }
            $l->write(t('Template Used') . ': ' . $this->template);
            $l->write(t('To') . ': ' . $toStr);
            $l->write(t('From') . ': ' . $fromStr);
            if (isset($this->replyto)) {
                $l->write(t('Reply-To') . ': ' . $replyStr);
            }
            $l->write(t('Subject') . ': ' . $this->subject);
            $l->write(t('Body') . ': ' . $this->body);
            $l->close();
        }		

        // clear data if applicable
        if ($resetData) {
            $this->to = array();
            $this->cc = array();
            $this->bcc = array();
            $this->replyto = array();
            $this->from = array();
            $this->template = '';
            $this->subject = '';
            $this->body = '';
            $this->bodyHTML = '';
        }
    }
}

Then Find /concrete/core/controllers/blocks/form.php. In the function action_submit_form() there is a spot that looks like

$mh = Loader::helper('mail');
$mh->to( $this->recipientEmail ); 
$mh->from( $formFormEmailAddress );
$mh->replyto( $replyToEmailAddress ); 
$mh->addParameter('formName', $this->surveyName);
$mh->addParameter('questionSetId', $this->questionSetId);
$mh->addParameter('questionAnswerPairs', $questionAnswerPairs); 
$mh->load('block_form_submission');
$mh->setSubject(t('%s Form Submission', $this->surveyName));
//echo $mh->body.'<br>';
@$mh->sendMail(); 

change that to

$mh = Loader::helper('mail');
$mh->to( $this->recipientEmail ); 
$mh->from( $formFormEmailAddress );
$mh->replyto( $replyToEmailAddress ); 
$mh->addParameter('formName', $this->surveyName);
$mh->addParameter('questionSetId', $this->questionSetId);
$mh->addParameter('questionAnswerPairs', $questionAnswerPairs); 
$mh->load('block_form_submission');
$mh->setSubject(t('%s Form Submission', $this->surveyName));
if (!empty($tmpFileIds)) {
    foreach ($tmpFileIds as $tmpFileId) {
        $mh->AddAttachmentById($tmpFileId);
    }
}
                                
//echo $mh->body.'<br>';
@$mh->sendMail(); 

Thats it!

Posted in CMS, PHP | Tagged c5, Concrete5, emails | Leave a response

Concrete5 on Godaddy with FastCgi

By Jason on July 15, 2013

.htaccess


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>

config/site.php


define('SERVER_PATH_VARIABLE', 'REQUEST_URI');

/php5.ini


cgi.fix_pathinfo = 1
cgi.force_redirect = 0

Posted in CMS | Tagged c5, Concrete5, fastcgi, godaddy | Leave a response

Some C5 Gallery Slider File set action

By Josh on March 7, 2013

So, I’ve been looking for some ready and simple ways to dump out images from the c5 file manager (as a file set, even) for use as a gallery, slider, whatever. I recently have implemented 2 different things, both of which worked pretty well depending on what you need.

First is: Sortable Fancybox Gallery – which is in the c5 marketplace, for free. I use it in rhinodeck.com (currently at http://www.rhinodeck.com/main-nav/products/armadillo/decking/armadillo-decking-solid/ (for the image carousel) and http://www.rhinodeck.com/main-nav/gallery/ for a general gallery layout. It might be overkill for very simple things, but worked well.

And then this:

ForĀ  http://scmg.mnwebdevelopment.com/ (st cloud medical soon) I found this very simple package called designer gallery: https://github.com/jordanlev/c5_designer_gallery. The name is a little silly, because it produces a very simple list of images from a file set… which is perfect for a lot of applications. In the SCMG case, I used it again with a carousel in the top banner.

Posted in CMS, Javascript | Tagged c5, carousel, Concrete5, fileset, gallery, slider | Leave a response

Google Translate and c5 edit mode

By Josh on October 10, 2012

I know I’ve seen this before, but posting ’cause it took me too long to remember WTF was causing it. If you use google translate on a c5 site, the trans script add positioning junk to your body. This causes the editable area highlighters to misalign, possibly making it nonfunctional. So i simply strip out the good trans code when in edit mode. Can be seen at Mahube.org or soon to be capsh.org. Suck it.

Posted in CMS, Google | Tagged c5, google translate | Leave a response

Speed up Concrete5

By Jason on March 5, 2012

Version 5.4.2.2 and possibly others have a bug in the caching code that causes sites to slow to a crawl. Add this to your site.php to fix it.

    define('CACHE_FRONTEND_OPTIONS', serialize(array('automatic_cleaning_factor' => 0)));

Edit:
The caching bug still seems to be there as of version 5.5.1

Posted in CMS | Tagged c5, Concrete5 | 1 Response

Next »

Tags

.htaccess Advanced Custom Fields Bower c5 cms Composer Concrete 5 Concrete5 Cron CSS3 Cycle Cycle2 fancybox FancyBox2 Foundation Genesis Google Fonts Google Maps Google Webfonts Google Web Fonts Gravity Forms Grunt html5 HTML5 Boilerplate IE7 iPad iPhone jQuery lightbox Lists Magento Media Queries mobile pdf Plesk PrettyPhoto Responsive SASS SCSS static block Twitter typekit Video WordPress YouTube

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Recent Comments

  • Bryce on Responsive Email Templates
  • Justin on Mail Server Settings (Microsoft365)
  • Justin on Mail Server Settings (Microsoft365)
  • Bryce on Mail Server Settings (Microsoft365)
  • Justin on Mail Server Settings (Microsoft365)

Authors

  • Aaron Huisinga
  • Bryce
  • Darin
  • Jason
  • Josh
  • Justin
  • master
  • Nathan
  • nick
  • Paul

Archives

  • March 2016
  • July 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • September 2014
  • July 2014
  • June 2014
  • May 2014
  • December 2013
  • November 2013

Copyright © 2023 Meta 13 Project Blog. Powered by WordPress and Hybrid.