Add Attachments to C5 Forms
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!
Concrete5 on Godaddy with FastCgi
.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
Google Translate and c5 edit mode
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.
Speed up Concrete5
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
Recent Comments