Magento Observer:无法发送标题;标头已经发送

时间:2015-10-14 17:55:23

标签: php magento magento-1.9

我一直在尝试创建一个Observer,它可以在创建发票后自动发送SMS,方法是挂钩:

  

sales_order_save_after

现在我收到错误消息:" a:5:{i:0;s:132:"Cannot send headers; headers already sent in /home2/uditgupta/public_html/app/code/local/Yng/AssignDealer/Model/Observer.php, line 4";i:1;s:1407:"#0 /home2/uditgupta/public_html/lib/Zend/Controller/Response/Abstract.php(148): Zend_Controller_Response_Abstract->canSendHeaders(true) "

这是我的代码:

class Yng_AssignDealer_Model_Observer {
    public function customerRegisterSuccess(Varien_Event_Observer $observer) {
        $order = $observer->getEvent()->getOrder();
        print_r($order->getData()); 
        echo $ordid = $order['increment_id']; 
        $orderObj = Mage::getModel('sales/order')->loadByIncrementId($ordid);
        print_r($orderObj);
        $billing_info=$orderObj->getBillingAddress();
        echo $mobile=$billing_info['telephone']; 
        echo $name=$billing_info['firstname'];
        if($order['status']=="processing")
        {   
            $msg='Hello';
            $path='http://login.smsgatewayhub.com/';
            $ch = curl_init($path);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
            curl_exec($ch);
            curl_close($ch);
            //echo $path;
        }
        if($order['status']=="complete")
        {       
            $msg='Hello';
            $path='http://login.smsgatewayhub.com/';
            $ch = curl_init($path);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
            curl_exec($ch);
            curl_close($ch);
            //echo $path;
        }
    }
}

请帮忙。非常感谢提前。

1 个答案:

答案 0 :(得分:-1)

从代码中删除echo和print_r然后检查