Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Add support for sile attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
bossanova808 committed Jan 5, 2017
1 parent 6f29c6c commit e53725c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions commercemailer/controllers/CommerceMailerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,27 @@ public function actionSendMail()
}
$compiledMessage .= $postedMessage['body'];
}
$vars['body'] = $compiledMessage;
$vars['body'] = "<br>" . nl2br($compiledMessage);
}
}
else
{
$vars['body'] = $postedMessage;
$vars['body'] = "<br>" . nl2br($postedMessage);
}
}


// create an EmailModel & populate it
$email = EmailModel::populateModel($vars);

//Attach a file if there is one...
$attachment = null;
if (isset($_FILES['attachment']) && !empty($_FILES['attachment']['name']))
{
CommerceMailerPlugin::log("Found attachment " . $_FILES['attachment']['name']);
$attachment = \CUploadedFile::getInstanceByName('attachment');
$email->addAttachment($attachment->getTempName(), $attachment->getName(), 'base64', $attachment->getType());
}

//validate the email model
//put all our errors in one place, and return the email model if invalid - use message as this is what contactForm does
Expand Down Expand Up @@ -185,6 +193,8 @@ public function actionSendMail()
foreach ($errors as $error) {
CommerceMailerPlugin::logError($error);
}
//Log what page the error happened on...
CommerceMailerPlugin::logError(craft()->request->getUrlReferrer());
craft()->urlManager->setRouteVariables(['errors' => $errors, 'message' => $email] );
}
else {
Expand All @@ -195,7 +205,7 @@ public function actionSendMail()
if (!$spam){

//Special sauce for us....
if (craft()->config->get('environmentVariables')['customMessaging']){
if (craft()->config->get('environmentVariables')['IsImageScience']){

//Are we sending to a local address?
if(strpos($email->toEmail, "@" . $settings->internalDomain) === false){
Expand All @@ -205,7 +215,7 @@ public function actionSendMail()
}
else{
//Make a freshdesk ticket with the API
$sent = craft()->businessLogic_freshdesk->ticket($email->fromEmail, $email->toEmail, $email->subject, $email->htmlBody, (isset($vars['order']) ? $vars['order'] : null) );
$sent = craft()->businessLogic_freshdesk->ticket($email->fromEmail, $email->toEmail, $email->subject, $email->htmlBody, (isset($vars['order']) ? $vars['order'] : null), false, $attachment);
}

}
Expand Down

0 comments on commit e53725c

Please sign in to comment.