1

First of my Guest controller code for a rest api call is as followed:

protected function _retrieveCollection() 
{
    try 
    {
        $email = $this->getRequest()->getParams('email');


         //check if email exists in db or not
         $customer = Mage::getModel("customer/customer");
         $customer->setWebsiteId(1);
         $customer->loadByEmail($email["email"]); //load customer by email i 

         if($customer->getId()>0){

             //send forgot password link
             $body = "Your forgot password link:- http://dev02-aws-sg01.zooyo.net/index.php/customer/account/changeforgotten/";
             $mail = Mage::getModel('core/email');
             $mail->setToEmail($email["email"]);
             $mail->setBody($body);
             $mail->setSubject('Forgot Password');
             $mail->setFromEmail('');
             $mail->setFromName("Admin");
             $mail->setType('html');// You can use 'html' or 'text'
             $mail->send();

             $array = array("status" => "200", "error" => "Email sent successfully.");
             return json_encode($array);
         }else{

             $array = array("status" => "500", "error" => "Email does not exists.");
             return json_encode($array);
         }


    } catch (Exception $e) {
        $array = array("status" => "500", "error" => "Error in sending email");
        return json_encode($array);
    }   
}

The route which I hit is:

http://localhost:81/magento/api/rest/forgetpass

The output is:

enter image description here

As you can see in the image the json string is coming inside xml which is wrong, I want fully the output in json format. But let me be clear i dont want to override any file in magento for application format type.

1

Replace $email = $this->getRequest()->getParams('email');

to $email = $this->getRequest()->getParam('email');

Also check that the email you are sending via GET or POST method is available in your database.

Hope this will help you

  • Can you let me know how this will help me to get the output. Becuase I did this and no changes I can see. – Akash Rai May 2 '16 at 6:51
  • You are using wrong syntax.. To get a single param you need to use ` $this->getRequest()->getParam('param');`. If this not help then try to check the param name may be there you are adding some space or there is some spelling mistake – Asish Hira May 2 '16 at 6:53
  • dev02-aws-sg01.zooyo.net/api/rest/forgetpass/…. Hit this url it will show success message showing inside xml. – Akash Rai May 2 '16 at 7:01
  • Then the email you are sending via get this email is not in your database – Asish Hira May 2 '16 at 7:03
  • 1
    The error clearly mention you that the email is not exist. As Asish said try to check the email exist on your database. – Mujahidh May 2 '16 at 7:30
0

you must have to set the From or sender email and it will be

$senderName = Mage::getStoreConfig('trans_email/ident_general/name'); $senderEmail = Mage::getStoreConfig('trans_email/ident_general/email');

$subject="Welcome ".$name;
$to="receiver_email"
$mail = Mage::getModel('core/email')
->setToName($senderName)
->setToEmail($to)
->setBody($message)
->setSubject($subject)
->setFromEmail($senderEmail)
->setFromName($senderName)
->setType('html');
$mail->send();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.