Set a different SMTP for Newsletter in Magento - magento

i was wondering if it's possible to set two different SMTP server on Magento:
one for the Newsletter and one for the Magento System emails.
I saw around that is possible to set SMTP in template.php but that will affect all the emails. Is then possible two different ones?
Thank you all !!
Ps:
I tried to modify the file /app/code/core/Mage/Newsletter/Model/Template.php
as suggested on post :
Magento - How enable SMTP server authentication and secure transport?
and used the code in this way:
public function getMail()
{
if (is_null($this->_mail)) {
/*Start of added code to specify config*/
$my_smtp_host = 'smtp.mysmtp.com'; // Take it from Magento backoffice or you can specify it here
$my_smtp_port = '587'; // Take it from Magento backoffice or you can specify it here
$config = array(
'port' => $my_smtp_port, //optional - default 25
'auth' => 'login',
'username' => 'mylogin#email.it',
'password' => 'mypassword'
);
$transport = new Zend_Mail_Transport_Smtp($my_smtp_host, $config);
Zend_Mail::setDefaultTransport($transport);
/*End of added code to specify config*/
$this->_mail = new Zend_Mail('utf-8');
}
return $this->_mail;
}
Unfortunatly is taking the system smtp instead of using this one.
I also commented the two lines:
ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
Any idea why is still using the system one?

Mail transport is set up and executed from these two functions
Mage_Core_Model_Email_Template -> send() in /app/code/core/Mage/Core/Model/Email/Template.php for Transactional Emails
Mage_Newsletter_Model_Template -> send() in /app/code/core/Mage/Newsletter/Model/Template.php for Newsletters
Here's the working module code I created to direct transactional emails through our email service provider. It is not a paste-in for the newsletter send() function!
Note that you will need to hard code the extra config items for your purposes as this code sample is missing the setup to add the fields to system config, but it should give you an idea of how the send() function needs to be changed for the Newsletter module. I personally don't use the Newsletter module as we have a service provider for promotional emails to keep from poisoning our domain by false flagging as a spam source.
public function send($email, $name = null, array $variables = array())
{
if (!$this->isValidForSend()) {
Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
return false;
}
/* Set up mail transport to Email Hosting Provider SMTP Server via SSL/TLS */
$config = array(
'ssl' => Mage::getStoreConfig('system/smtp/ssl'), // option of none, ssl or tls
'port' => Mage::getStoreConfig('system/smtp/port'), // TLS 587 - SSL 465 - default 25
'auth' => Mage::getStoreConfig('system/smtp/auth'), // Auth type none, login, plain, CRAM-MD5
'username' => Mage::getStoreConfig('system/smtp/username'),
'password' => Mage::getStoreConfig('system/smtp/password')
);
/* Set up transport package to host */
$transport = new Zend_Mail_Transport_Smtp(Mage::getStoreConfig('system/smtp/host'), $config);
/* End transport setup */
$emails = array_values((array)$email);
$names = is_array($name) ? $name : (array)$name;
$names = array_values($names);
foreach ($emails as $key => $email) {
if (!isset($names[$key])) {
$names[$key] = substr($email, 0, strpos($email, '#'));
}
}
$variables['email'] = reset($emails);
$variables['name'] = reset($names);
// ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
// ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
$mail = $this->getMail();
$setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
switch ($setReturnPath) {
case 1:
$returnPathEmail = $this->getSenderEmail();
break;
case 2:
$returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
break;
default:
$returnPathEmail = null;
break;
}
if ($returnPathEmail !== null) {
$mailTransport = new Zend_Mail_Transport_Sendmail("-f".$returnPathEmail);
Zend_Mail::setDefaultTransport($mailTransport);
}
foreach ($emails as $key => $email) {
$mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
}
$this->setUseAbsoluteLinks(true);
$text = $this->getProcessedTemplate($variables, true);
if($this->isPlain()) {
$mail->setBodyText($text);
} else {
$mail->setBodyHTML($text);
}
$mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=');
$mail->setFrom($this->getSenderEmail(), $this->getSenderName());
try {
/* Send Transport, empty and log success */
$mail->send($transport); //transport object
$this->_mail = null;
Mage::log('Mailed to: ' . $this->getSenderEmail() . ' ' . $this->getSenderName() . ' ' .$this->getProcessedTemplateSubject($variables), null, 'email.log');
/* End */
}
catch (Exception $e) {
/* Or empty and log failure */
$this->_mail = null;
Mage::log('Failure: ' . $e, null, 'email.log');
Mage::logException($e);
return false;
/* End */
}
return true;
}

Related

Authorize.Net subscription using CustomerProfileId Error E00121 Laravel PHP

I have an existing customer that has authorize.net profiled. I wanted to make a subscription based on the customerProfileId provided by authorize.net.
I am using these instructions from their developer website
https://developer.authorize.net/api/reference/index.html#recurring-billing-create-a-subscription-from-customer-profile
upon running, I am receiving this error message.
Response : E00121 No default payment/shipping profile found.
Laravel PHP Code
public function createSubscription($request, $customerProfileId, $customerPaymentProfileId, $customerAddressId = null)
{
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(config('services.authorize.login'));
$merchantAuthentication->setTransactionKey(config('services.authorize.key'));
// Set the transaction's refId
$refId = 'ref' . time();
// Subscription Type Info
$subscription = new AnetAPI\ARBSubscriptionType();
$subscription->setName("USLOCAL Subscription");
$interval = new AnetAPI\PaymentScheduleType\IntervalAType();
$interval->setLength("1");
$interval->setUnit("months");
$paymentSchedule = new AnetAPI\PaymentScheduleType();
$paymentSchedule->setInterval($interval);
$paymentSchedule->setStartDate(new \DateTime($request->due_date));
$paymentSchedule->setTotalOccurrences("999");
/* $paymentSchedule->setTrialOccurrences("1"); */
$subscription->setPaymentSchedule($paymentSchedule);
$subscription->setAmount($this->amount);
/* $subscription->setTrialAmount("0.00"); */
$profile = new AnetAPI\CustomerProfileIdType();
$profile->setCustomerProfileId($customerProfileId);
$profile->setCustomerPaymentProfileId($customerPaymentProfileId);
if ($customerAddressId) {
$profile->setCustomerAddressId($customerAddressId);
}
$subscription->setProfile($profile);
$request = new AnetAPI\ARBCreateSubscriptionRequest();
$request->setmerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setSubscription($subscription);
$controller = new AnetController\ARBCreateSubscriptionController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok")) {
return [
'success' => true,
'message' => "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n",
];
} else {
$errorMessages = $response->getMessages()->getMessage();
return [
'success' => false,
'message' => "Response : " . $errorMessages[0]->getCode() . " " . $errorMessages[0]->getText() . "\n",
];
}
return [
'success' => false,
'message' => $response,
];
}
Authorize.net: Sandbox Customer Account.
Does anyone have an idea why I am getting this error message?
Note that this is a service provider and shipping address should not be required.

How to call shell function to another Controller - Cakephp

I'm using this function in my shell to send email
Edit :
UsersShell
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Log\Log;
use Cake\Controller\Component;
use Cake\Controller\ComponentRegistry;
use App\Controller\Component\EmailComponent;
class UsersShell extends Shell
{
public function initialize()
{
parent::initialize();
$this->loadModel('Users');
//Load Component
$this->Email = new EmailComponent(new ComponentRegistry());
}
public function mail()
{
$to = 'exemple#gmail.com';
$subject = 'Hi buddy, i got a message for you.';
$message = 'User created new event';
try {
$mail = $this->Email->send_mail($to, $subject, $message);
print_r($mail);
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail-
>ErrorInfo;
}
exit;
}
I would like to know how can I call it in my controller ? here
Edit : Events is located in the plugins folder
EventsController
<?php
namespace FullCalendar\Controller;
use FullCalendar\Controller\FullCalendarAppController;
use Cake\Routing\Router;
use Cake\Event\Event;
use Cake\Console\ShellDispatcher;
class EventsController extends FullCalendarAppController
{
public $name = 'Events';
public function add()
{
$event = $this->Events->newEntity();
if ($this->request->is('post')) {
$event = $this->Events->patchEntity($event, $this->request->data);
if ($this->Events->save($event)) {
/* $shell = new ShellDispatcher();
$output = $shell->run(['cake', 'users'], ['plugin' =>
'Events']);
if (0 === $output) {
$this->Flash->success('Success from shell command.');
} else {
$this->Flash->error('Failure from shell command.'); */
$this->Flash->success(__('The event has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The event could not be saved. Please,
try again.'));
}
}
$this->set('eventTypes', $this->Events->EventTypes->find('list'));
$this->set(compact('event'));
$this->set('_serialize', ['event']);
$this->set('user_session', $this->request->session()-
>read('Auth.User'));
$this->viewBuilder()->setLayout('user');
}
As you can see i used the shell dispatched i'm not sure if it's correct
but i'm getting failure
Thanks !
Edit :
EmailComponent
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
use Cake\Core\App;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require ROOT. '/vendor/phpmailer/phpmailer/src/Exception.php';
require ROOT. '/vendor/phpmailer/phpmailer/src/PHPMailer.php';
require ROOT. '/vendor/phpmailer/phpmailer/src/SMTP.php';
class EmailComponent extends Component {
public function send_mail($to, $subject, $message)
{
// date_default_timezone_set('Asia/Calcutta');
$sender = "exemple#gmail.com"; // this will be overwritten by GMail
$header = "X-Mailer: PHP/".phpversion() . "Return-Path: $sender";
$mail = new PHPMailer();
$mail->SMTPDebug = 2; // turn it off in production
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = "exemple#gmail.com";
$mail->Password = "xxxx";
$mail->SMTPSecure = "tls"; // ssl and tls
$mail->Port = 587; // 465 and 587
$mail->SMTPOptions = array (
'tls' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
),
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->From = $sender;
$mail->FromName = "From Me";
$mail->AddAddress($to);
$mail->isHTML(true);
$mail->CreateHeader($header);
$mail->Subject = $subject;
$mail->Body = nl2br($message);
$mail->AltBody = nl2br($message);
// return an array with two keys: error & message
if(!$mail->Send()) {
return array('error' => true, 'message' => 'Mailer Error: ' . $mail->ErrorInfo);
} else {
return array('error' => false, 'message' => "Message sent!");
}
}
}
Correct me if I'm wrong. First your shell must be started something like this.
class UsersShell extends AppShell {
public function main(){ //change name here to main
$to = 'exemple#gmail.com';
$subject = 'Hi buddy, i got a message for you.';
$message = 'User created new event';
try {
$mail = $this->Email->send_mail($to, $subject, $message);
print_r($mail);
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
exit;
}
}
By the way, if you want to check output, you must return something like true or false. Otherwise, there is no point to check output after execute the shell.
First Check Shell Command Run in CakePHP-CLI. Like this
bin/cake users mail
if shell command successfully running. Shell Class Fine.
Next Use Shell in Controller
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Console\ShellDispatcher;
class PagesController extends AppController
{
/**
* Run shell command
*/
public function run()
{
$shell = new ShellDispatcher();
$output = $shell->run(['cake', 'users', 'mail']);
// $output = $shell->run(['cake', 'users', 'mail', 'email']); // [pass arguments]
// debug($output);
if ($output === 0) {
echo "Shell Command execute";
} else {
echo "Failure form shell command";
}
exit;
}
}
Change Shell Function : if mail not sent run $this->abort() function and return (int) 1 and mail sent successfully run $this->out() function and return (int) 0
/**
* Send Mail with shell command
*/
public function mail()
{
$to = 'mail#gmail.com';
$subject = 'Hi buddy, i got a message for you.';
$message = 'Nothing much. Just test out my Email Component using PHPMailer.';
$mail = $this->Email->send_mail($to, $subject, $message);
// debug($mail);
if ($mail['error'] === false) {
$this->out("Mail Successfully Sent For :: ". $to);
} else {
$this->abort("Mail Error.");
}
}

Sending multiple messages with swiftmailer - PHP

I'm trying to send e-mails using swiftmailer. I want to send a message to someone who fills out a form, and to myself. The script I use below is sending the first of the two messages, but the second one never arrives. How can I solve this?
$transport = Swift_SmtpTransport::newInstance('smtp.mysite.nl', 25)
->setUsername('myusername')
->setPassword('mypassword')
;
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = Swift_Message::newInstance()
// Set the content type
/* ->setContentType("text/html"); */
// Give the message a subject
->setSubject("mysubject")
// Set the From address with an associative array
->setFrom(array('email#email.com' => "emailer"))
// Set the To addresses with an associative array
->setTo(array('email#email.com' => "emailer"))
// Give it a body
->setBody('My message', 'text/html');
// Create the message
$message2 = Swift_Message::newInstance()
// Set the content type
/* ->setContentType("text/html"); */
// Give the message a subject
->setSubject("mysubject")
// Set the From address with an associative array
->setFrom(array('email#email.com' => "emailer"))
// Set the To addresses with an associative array
->setTo(array('email#email.com' => "emailer"))
// Give it a body
->setBody('My message', 'text/html');
$result = $mailer->send($message, $message2);
In short: $message is sent, $message2 is not sent. I DO NOT GET ANY ERRORS FROM THIS SCRIPT!
Try to use something like:
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setBody('Here is the message itself');
// Send the message
$failedRecipients = array();
$numSent = 0;
$to = array('receiver#domain.org', 'other#domain.org' => 'A name');
foreach ($to as $address => $name)
{
if (is_int($address)) {
$message->setTo($name);
} else {
$message->setTo(array($address => $name));
}
$numSent += $mailer->send($message, $failedRecipients);
}
printf("Sent %d messages\n", $numSent);
Such services usually have different methods of sending multiple emails.
Try sending it one bye one.
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('yourUsername')
->setPassword('yourPassword');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Your message')
->setFrom(array('enquiries#dtect.com' => 'Enquiry'))
->setTo(array('enquiries#dtect.com'))
->setBody("Body content");
$result = $mailer->send($message);
$mailer2 = Swift_Mailer::newInstance($transport);
$message2 = Swift_Message::newInstance('Dtect Report Portal - '.$typeOfEnquiry)
->setFrom(array('enquiries#dtect.com' => 'Enquiry'))
->setTo($emailAddress)
->setBody("Dear ".$name.","."\r\n".
"Thank you for contacting us"."\r\n".
"We will respond to your enquiry as soon as possible"."\r\n".
"Regards");
$result2 = $mailer2->send($message2);
Hope this help.

How to auto fill shipping method Magento for onepagechekout

I want to auto fill the shipping method automatically and not show it on the onepage checkout. I was able to hide the shipping method on my Onepagechekout by changing this on app/code/local/Mage/Checkout/controllers/OnepageController.php:
/**
* save checkout billing address
*/
public function saveBillingAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
// $postData = $this->getRequest()->getPost('billing', array());
// $data = $this->_filterPostData($postData);
$data = $this->getRequest()->getPost('billing', array());
$customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
if (isset($data['email'])) {
$data['email'] = trim($data['email']);
}
$result = $this->getOnepage()->saveBilling($data, $customerAddressId);
if (!isset($result['error'])) {
/* check quote for virtual */
if ($this->getOnepage()->getQuote()->isVirtual())
{
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
} elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1)
{
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
$result['allow_sections'] = array('shipping');
$result['duplicateBillingInfo'] = 'true';
} else {
$result['goto_section'] = 'shipping';
}
}
$this->saveShippingMethodAction();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
As you can see I changed the link where I redirect the next step after billing action to the payment step.
In order to auto-save a shipping method, I added
$this->saveShippingMethodAction();
at the end of the function, and this method looks like here:
public function saveShippingMethodAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
/* $this->savePaymentAction(); */
$data = $this->getRequest()->getPost('shipping_method', 'flatrate_flatrate');
$result = $this->getOnepage()->saveShippingMethod($data);
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
So what I did is try to include automatically flatrate_flatrate method as the default one.
But when I try to finish a sale, it says I didn't specify a shipping method. Any idea on why it doesn't work?
Now you need to force the shipping_method in the quote and in the session :
$forcedMethod = "your_method_code";
$this->getOnePage()->getQuote()
->getShippingAddress()
->setShippingMethod($forcedMethod)
->save();
Mage::getSingleton('checkout/session')->setShippingMethod($forcedMethod);
And just before you call :
$this->saveShippingMethodAction();
add a :
$this->getRequest()->setPost('shipping_method', $forcedMethod);
It should work ;)

Incorrect Signature in facebook stream_publish call

I am having a facebook error on stream_publish call. I actually used an extension for Magento for Fconnect. Fconnect & Flogin is working fine. But it is requirement that when user place an order it should be posted on user's wall. For that I have implemented like this
document.observe('click', function(e){
if (e.element().match('a[rel^=facebook-connect]') || e.element().match('button[rel^=facebook-connect]')) {
e.stop();
FB.login(function(response){
if(response.status=='connected') setLocation('http://staging.mystore.com/facebook/customer_account/connect/');
}, {perms:"email,publish_stream"});
}
});
in Facebook Client file generateSignature method is like this
private function _generateSig($params_array)
{
Mage::log($params_array);
$str = '';
ksort($params_array);
foreach ($params_array as $k=>$v) {
$str .= "$k=$v";
}
$str .= $this->_secret;
Mage::log($str);
Mage::log('md5 sigs:: ' . md5($str));
return md5($str);
}
& My code that is calling the API is like this
$message = 'just placed an order on mystore.com';
$attachment = array(
'name' => "mystore",
'href' => 'http://www.mystore.com/',
'description' => 'New order on mystore.com',
'media' => array(array('type' => 'image',
'src' => 'http://www.mystore.com/skin/frontend/default/mystore/images/logo.png',
'href' => 'http://www.mystore.com/')));
$action_links = array( array('text' => 'Buy#mystore', 'href' => 'http://www.mystore.com/'));
$attachment = json_encode($attachment);
$action_links = json_encode($action_links);
try{
// if( $facebook->api_client->stream_publish($message, $attachment, $action_links, null, $target_id))
if($this->_getClient()->call( 'facebook.stream.publish',
array($message, $attachment, $action_links,
$this->_getClient()->users->getLoggedInUser(),
Mage::getSingleton('facebook/config')->getApiKey() )
) )
{
Mage::log( "Added on FB Wall" );
}
} catch(Exception $e)
{
Mage::log( "Exception in wall write" );
Mage::log($e);
}
After logging the Signature I found in log is
api_key=XXXXXXXXmethod=facebook.stream.publishsession_key=2.AQCm5fABfobInAS5.3600.1309352400.1-1000025660978090=just placed an order on mystore.comcall_id=1309345883.3068format=JSONv=1.01={"name":"mystore","href":"http:\/\/www.mystore.com\/","description":"New order on mystore.com","media":[{"type":"image","src":"http:\/\/www.mystore.com\/skin\/frontend\/default\/mystore\/images\/logo.png","href":"http:\/\/www.mystore.com\/"}]}2=[{"text":"Buy#mystore","href":"http:\/\/www.mystore.com\/"}]3=1000025660978094=5070afefb42b162aff748f55ecf44d110d9e2a90117ee1704e2adb41f1d190fa
I have never done any development on Facebook SO I have no Idea what to do? Please help me with solution. & let me know if u guys need any other info to understand this.
Oh yeah One more thing the Client File code that is calling Api (call method) its like this
private function _prepareParams($method, $params)
{
$defaultParams = array(
'api_key' => $this->_apiKey,
'call_id' => microtime(true),
'format' => 'JSON',
'v' => '1.0'
);
if($this->_sessionKey){
$defaultParams['session_key'] = $this->_sessionKey;
}
$params = array_merge($defaultParams, $params);
foreach ($params as $key => &$val) {
if (!is_array($val)) continue;
$val = Zend_Json::encode($val);
}
$params['method'] = $method;
if(isset($params['sig'])) {
unset($params['sig']);
}
$params['sig'] = $this->_generateSig($params);
return $params;
}
public function call($method, $args=array())
{
Mage::log($args);
$params = $this->_prepareParams($method, $args);
$client = self::_getHttpClient()
->setUri(self::FACEBOOK_REST_URI)
->setMethod(Zend_Http_Client::POST)
->resetParameters()
->setParameterPost($params);
try {
$response = $client->request();
} catch(Exception $e) {
throw new Mage_Core_Exception('Service unavaliable');
}
if(!$response->isSuccessful()) {
throw new Mage_Core_Exception('Service unavaliable');
}
$result = Zend_Json::decode($response->getBody());
//json decode returns float on long uid number? is_json check? old php?
if(is_float($result)){
$result = $response->getBody();
}
if(is_array($result) && isset($result['error_code'])) {
throw new Mage_Core_Exception($result['error_msg'], $result['error_code']);
}
return $result;
}
For calling API I used two ways $this->_getClient()->call( 'facebook.stream.publish',
& $this->_getClient()->call( 'stream_publish',
None of them are working
ok GUys I figure out the mistake
look at my code
format=JSONv=1.01={"name":"mystore","href":"http:\/\/www.mystore.com\/","description":"New order on mystore.com","media":[{"type":"image","src":"http:\/\/www.mystore.com\/skin\/frontend\/default\/mystore\/images\/logo.png","href":"http:\/\/www.mystore.com\/"}]}2=[{"text":"Buy#mystore","href":"http:\/\/www.mystore.com\/"}]3=1000025660978094=5070afefb42b162aff748f55ecf44d110d9e2a90117ee1704e2adb41f1d190fa
where u can see format=JSONv=1.01={....}2=[{.....}] the problem was I used numeric arrays for parameters. they should be associated arrays
like message={new order}attachment={....}
Once I fixed the associative array problem my code start working correctly
here is a link that'll give u detail about parameters to pass to stream.publish
http://schoolout.net/en/developers/view/39
Hope this will help somebody else too.

Resources