ovh / php-ovh-sms

PHP for ovh sms API
Other
48 stars 49 forks source link

setSender does not work #23

Closed Strategy47 closed 7 years ago

Strategy47 commented 7 years ago

Hi, When I send an SMS from https://www.ovhtelecom.fr/manager with my sender that work.

When I do this with PHP the sms is never sent and the manager confirms this

    /**
     * @Route("confirmphone", name="app_phone_confirmation")
     * @Method({"POST"})
     */
    public function confirmationSmsAction(Request $request)
    {
        $phone = substr(str_replace(' ', '', $request->get('phone')), 1);

        $Sms = new SmsApi( 
            $this->getParameter('ovh_api_key'),
            $this->getParameter('ovh_api_secret'),
            'ovh-eu',
            $this->getParameter('ovh_api_consumer')
        );

        $accounts = $Sms->getAccounts();

        $Sms->setAccount($accounts[0]);
        $senders = $Sms->getSenders();
        $Message = $Sms->createMessage();
        $Message->setSender($senders[0]);  

        $Message->addReceiver('+33'.$phone);
        $Message->setIsMarketing(false);

        $res = $Message->send("Hello world!");

        return $this->json( $res );
    }

If i remove $Message->setSender($senders[0]); that work

    $( "#fos_user_registration_form_phone" ).blur(function() {
        var phone = $(this).val();
        $.post( "{{ path('app_phone_confirmation') }}", {phone: phone}, function( data ) {
            console.log( data );
        });
    });

And the api response is:

array(7) {
  ["comment"]=>
  string(0) ""
  ["sender"]=>
  string(7) "AChasse"
  ["status"]=>
  string(6) "enable"
  ["type"]=>
  string(5) "alpha"
  ["description"]=>
  string(9) "addsender"
  ["referer"]=>
  string(6) "custom"
  ["validationMedia"]=>
  string(10) "moderation"
}

Thank you for your help

Strategy47 commented 7 years ago

Ok sorry an error of my ;)