Email Template goes as Raw Html using Swiftmailer Symfony2 - symfony-2.8

Hi I am sending email templates to email as followas:
//here $emailBody is a twig template with html.
$mailBody = $this->templating->render('test/template/layout.html.twig', array(
'mailBody' => $mailBody
));
$tmp = $this->mailer->createMessage();
$tmp->setSubject(trim($emailSubject));
$tmp->setFrom('test#gmail.com');
$tmp->setTo($somnerecipeient);
$tmp->setBody($emailBody, 'text/html');
$sent = $this->mailer->send($tmp);
So when I am geting email my inbox its comes like raw html.Even content-type is already set text/html as:
$tmp->setBody($emailBody, 'text/html');
What could be the issue, Please assist
Thanks advance

You should be using renderView and you spelled the content as $mailBody instead of $emailBody. So change like so:
$emailBody = $this->templating->renderView('test/template/layout.html.twig', array(
'mailBody' => $mailBody
));
Can you try that and see if it resolves the issue.

Related

Yii2 - Generate Pdf on the fly and attach to email

This is how I can generate pdf page
public function actionPdf(){
Yii::$app->response->format = 'pdf';
$this->layout = '//print';
return $this->render('myview', []);
}
And this is how I send emails
$send = Yii::$app->mailer->compose('mytemplate',[])
->setFrom(Yii::$app->params['adminEmail'])
->setTo($email)
->setSubject($subject)
->send();
How I can generate pdf as a file and attach it to my emails on the fly?
Mailer have method called attachContent(), where you can put pdf file.
PDF should be rendered with output destination set as string, and then pass it as param to attachContent().
Sample:
Yii::$app->mail->compose()
->attachContent($pathToPdfFile, [
'fileName' => 'Name of your pdf',
'contentType' => 'application/pdf'
])
// to & subject & content of message
->send();
This is how I did it
In my controller:
$mpdf=new mPDF();
$mpdf->WriteHTML($this->renderPartial('pdf',['model' => $model])); //pdf is a name of view file responsible for this pdf document
$path = $mpdf->Output('', 'S');
Yii::$app->mail->compose()
->attachContent($path, ['fileName' => 'Invoice #'.$model->number.'.pdf', 'contentType' => 'application/pdf'])
This is how I sent mails in Yii2
private function sendPdfAsEmail($mpdf)
{
$mpdf->Output('filename.pdf', 'F');
$send = Yii::$app->mailer->compose()
->setFrom('admin#test.com')
->setTo('to#gmail.com')
->setSubject('Test Message')
->setTextBody('Plain text content. YII2 Application')
->setHtmlBody('<b>HTML content.</b>')
->attach(Yii::getAlias('#webroot').'/filename.pdf')
->send();
if($send) {
echo "Send";
}
}
Pass the mpdf instance to our custom function.
Use the F option in mpdf to save the output as a file.
use the attach option in Yii mailer and set the path of the saved file.

Shopify API Updating Fulfillments

I am writing a private app in Shopify with PHP. I have been able to get most of the other access to the json data, however, I am having trouble with Fulfillments - specifically updating a single line-item.
I am using the api-skeleton (phpish)?
Here is my code (the process as described seems so simple):
$orderid = "1350520065";
$itemid = "2338134657";
$quantity = 1;
$arguments = array(
'fulfillment' => array(
'tracking_number' => null,
'notify_customer' => true,
'line_items' => array(array('id' => $itemid, 'quantity' => 1))
)
);
$response = $shopify('POST /admin/orders/' . $orderid . '/fulfillments.json', $arguments);
I am getting [line_items] => Required parameter missing or invalid.
Any help would be appreciated.
Skip the line items unless you are doing a partial fulfillment. If you are, then obviously you need a quantity. You forgot that it seems, hence your error of missing parameter.
Add a header 'Content-Type:application/json' to your POST. That worked for me.

TYPO3 6.2x extBase RTE parse

I want to parse RTE content in TYPO3 6.2.9 extBase. I have tried:
$cObj = GeneralUtility::makeInstance('tslib_cObj');
$parseContent= $cObj->parseFunc($content, array(), '< lib.parseFunc_RTE');
$parseContent=\TYPO3\CMS\Frontend\Plugin\AbstractPlugin::pi_RTEcssText($content);
$cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
parseContent= $cObj->parseFunc($content, array(), '< lib.parseFunc_RTE' );
screenshot of the resulting html
How can I parse RTE content?
$Cobj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_cObj');
$htmloutput= $Cobj->parseFunc($myquerywithcontentvariable , array(), '< lib.parseFunc_RTE');
And of course Also use defaultExtras' => 'richtext:rte_transform[flag=rte_enabled|mode=ts_css] in your TCA file
Here is the function for the same
private function formatHtml($value) {
$contentObject = GeneralUtility::makeInstance(TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
$content = $contentObject->parseFunc($value, array(), '< lib.parseFunc_RTE');
return $content;
}
Alongwith RTE option enableRichText="1" please append this option as well defaultExtras="richtext:rte_transform[flag=rte_enabled|mode=ts_css]"
This might help :)
$parseProcObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
$parseProcObj->parseFunc($value, array(), '< lib.parseFunc_RTE')

BOX-API upload file form

i'm trying to upload a file in BOX_API with php and Zend framework. But i'm missing somethin. It's the first time that i use an interface like this o i've read the manual. But it is confusig for me. My question are two:
-First, why do you have to pass to the post call only the name of the file and not the whole file with the right header for file upload? File upload in a form is not like passing the name of the file through a post call;
-secondly and consequently, do i have to make a form for file upload or simply a textarea where to write the name of the file to be passed to the BOX-API?
UPDATE:
This is the code of my upload form:
$form = new Zend_Form;
$form->setAction('/imball-reagens/public/upload')
->setMethod('post');
$file = new Zend_Form_Element_File('file');
$file->setLabel('Choose a file to upload:');
$file->addValidator('alnum');
$file->setRequired(true);
$form->addElement($file);
$access_token = new Zend_Form_Element_Hidden(array('name' => 'access_token', 'value' => $result->access_token));
$form->addElement($access_token);
$refresh_token = new Zend_Form_Element_Hidden(array('name' => 'refresh_token', 'value' => $result->refresh_token));
$form->addElement($refresh_token);
$form->addElement('submit', 'upload', array('label' => 'Upload File'));
echo $form;
And this s the POST cal to the box API which comes after the form:
$access_token= $this->getRequest()->getParam('access_token');
$client = new Zend_Http_Client('https://upload.box.com/api/2.0/files/content');
$client->setMethod(Zend_Http_Client::POST);
$client->setHeaders('Authorization: Bearer '.$access_token);
$data = $_FILES["file"]["name"];
$client->setParameterPost(array(
'filename' => '#'.$data,
'parent_id' => '0'
));
$response = $client->request()->getBody();
$this->view->response= $response;
$result = json_decode($response);
The error it throws is below:
{"type":"error","status":400,"code":"invalid_request_parameters","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Invalid input parameters in request","request_id":"172518183652dcf2a16af73"}
Tricky to debug without seeing all of the code, but in the bit you pasted it looks like you are passing $_FILES["file"]["name"] to the API - this only contains the original name of the file which was uploaded by the user - you need to pass the location to the file on the server which is sending the data to the Box API client so that it can grab it and send it to the Box server - this should be stored in $_FILES["file"]["tmp_name"].
I would recommend changing the code to this and trying again:
$access_token= $this->getRequest()->getParam('access_token');
$client = new Zend_Http_Client('https://upload.box.com/api/2.0/files/content');
$client->setMethod(Zend_Http_Client::POST);
$client->setHeaders('Authorization: Bearer '.$access_token);
$data = $_FILES["file"]["tmp_name"];
$client->setParameterPost(array(
'parent_id' => '0'
));
$client->setFileUpload($data, 'filename');
$response = $client->request()->getBody();
$this->view->response= $response;
$result = json_decode($response);

Pulling the title of a wall post

just wondering if there is a way, using the API, to pull out the post title and desc separately? Essentially I would like this:
$post['author'] = $p['from'];
$post['title'] = $p['?'];
$post['content'] = $p['?'];
thanks
edit. I would also be happy with pulling just the title of a new post...
edit2. my mistake, there is no title in facebook posts. my coffee finally kicked in and my ignorance was revealed to me.
Try this http://www.wescutshall.com/2011/12/getting-facebook-user-data-with-php/
As you can see, you need some special permission from FB to get the data you need.
After that you can use their api, as described in the url before, to get your data.
EDIT:
Here you can see wich info you can get of a person:
http://developers.facebook.com/docs/reference/login/extended-profile-properties/
And here, wich you can get of a message (user_status):
http://developers.facebook.com/docs/reference/fql/location_post/
after you have this you can pull out the information using:
$config = array(
‘appId’ => FBAPPID,
‘secret’ => FBAPPSECRET,
);
$facebook = new Facebook($config);
$fbuserid = $facebook->getUser();
$params = array(
“scope” => “user_status”,
“redirect_uri” => “http://www.yoursite.com/”
);
$loginurl = $facebook->getLoginUrl($params);