Now Hiring: Are you a driven and motivated 1st Line IT Support Engineer?

Send Bulk Messages – PHP Integration

CODE SAMPLE

  • </pre>
    <pre class="prettyprint prettyprinted"><span class="pln">$messages </span><span class="pun">=</span><span class="pln"> array</span><span class="pun">();</span>
    
    <span class="kwd">for</span> <span class="pun">(</span><span class="pln">$i </span><span class="pun">=</span> <span class="lit">1</span><span class="pun">;</span><span class="pln"> $i </span><span class="pun"><=</span> <span class="lit">12</span><span class="pun">;</span><span class="pln"> $i</span><span class="pun">++)</span> <span class="pun">{</span><span class="pln">
        array_push</span><span class="pun">(</span><span class="pln">$messages</span><span class="pun">,</span>
            <span class="pun">[</span>
                <span class="str">"number"</span> <span class="pun">=></span> <span class="str">"+11234567890"</span><span class="pun">,</span>
                <span class="str">"message"</span> <span class="pun">=></span> <span class="str">"This is a test #{$i} of PHP version. Testing bulk message functionality."</span>
            <span class="pun">]);</span>
    <span class="pun">}</span>
    
    <span class="kwd">try</span> <span class="pun">{</span>
        <span class="com">// Send messages using the primary device.</span><span class="pln">
        sendMessages</span><span class="pun">(</span><span class="pln">$messages</span><span class="pun">);</span>
    
        <span class="com">// Send messages using default SIM of all available devices. Messages will be split between all devices.</span><span class="pln">
        sendMessages</span><span class="pun">(</span><span class="pln">$messages</span><span class="pun">,</span><span class="pln"> USE_ALL_DEVICES</span><span class="pun">);</span>
    	
        <span class="com">// Send messages using all SIMs of all available devices. Messages will be split between all SIMs.</span><span class="pln">
        sendMessages</span><span class="pun">(</span><span class="pln">$messages</span><span class="pun">,</span><span class="pln"> USE_ALL_SIMS</span><span class="pun">);</span>
    
        <span class="com">// Send messages using only specified devices. Messages will be split between devices or SIMs you specified.</span>
        <span class="com">// If you send 12 messages using this code then 4 messages will be sent by Device ID 1, other 4 by SIM in slot 1 of </span>
        <span class="com">// Device ID 2 (Represendted as "2|0") and remaining 4 by SIM in slot 2 of Device ID 2 (Represendted as "2|1").</span><span class="pln">
        sendMessages</span><span class="pun">(</span><span class="pln">$messages</span><span class="pun">,</span><span class="pln"> USE_SPECIFIED</span><span class="pun">,</span> <span class="pun">[</span><span class="lit">1</span><span class="pun">,</span> <span class="str">"2|0"</span><span class="pun">,</span> <span class="str">"2|1"</span><span class="pun">]);</span>
        
        <span class="com">// Send messages on schedule using the primary device.</span><span class="pln">
        sendMessages</span><span class="pun">(</span><span class="pln">$messages</span><span class="pun">,</span> <span class="kwd">null</span><span class="pun">,</span> <span class="kwd">null</span><span class="pun">,</span><span class="pln"> strtotime</span><span class="pun">(</span><span class="str">"+2 minutes"</span><span class="pun">));</span>
        
        <span class="com">// Send a message to contacts in contacts list with ID of 1.</span><span class="pln">
        sendMessageToContactsList</span><span class="pun">(</span><span class="lit">1</span><span class="pun">,</span> <span class="str">"Test"</span><span class="pun">,</span><span class="pln"> USE_SPECIFIED</span><span class="pun">,</span> <span class="lit">1</span><span class="pun">);</span>
        
        <span class="com">// Send a message on schedule to contacts in contacts list with ID of 1.</span><span class="pln">
        sendMessageToContactsList</span><span class="pun">(</span><span class="lit">1</span><span class="pun">,</span> <span class="str">"Test"</span><span class="pun">,</span> <span class="kwd">null</span><span class="pun">,</span> <span class="kwd">null</span><span class="pun">,</span><span class="pln"> strtotime</span><span class="pun">(</span><span class="str">"+2 minutes"</span><span class="pun">));</span>
        
        <span class="com">// Array of image links to attach to MMS message;</span><span class="pln">
        $attachments </span><span class="pun">=</span> <span class="pun">[</span>
            <span class="str">"https://example.com/images/footer-logo.png"</span><span class="pun">,</span>
            <span class="str">"https://example.com/downloads/sms-gateway/images/section/create-chat-bot.png"</span>
        <span class="pun">];</span><span class="pln">
        $attachments </span><span class="pun">=</span><span class="pln"> implode</span><span class="pun">(</span><span class="str">','</span><span class="pun">,</span><span class="pln"> $attachments</span><span class="pun">);</span><span class="pln">
        
        $mmsMessages </span><span class="pun">=</span> <span class="pun">[];</span>
        <span class="kwd">for</span> <span class="pun">(</span><span class="pln">$i </span><span class="pun">=</span> <span class="lit">1</span><span class="pun">;</span><span class="pln"> $i </span><span class="pun"><=</span> <span class="lit">12</span><span class="pun">;</span><span class="pln"> $i</span><span class="pun">++)</span> <span class="pun">{</span><span class="pln">
            array_push</span><span class="pun">(</span><span class="pln">$mmsMessages</span><span class="pun">,</span>
                <span class="pun">[</span>
                    <span class="str">"number"</span> <span class="pun">=></span> <span class="str">"+11234567890"</span><span class="pun">,</span>
                    <span class="str">"message"</span> <span class="pun">=></span> <span class="str">"This is a test #{$i} of PHP version. Testing bulk MMS message functionality."</span><span class="pun">,</span>
                    <span class="str">"type"</span> <span class="pun">=></span> <span class="str">"mms"</span><span class="pun">,</span>
                    <span class="str">"attachments"</span> <span class="pun">=></span><span class="pln"> $attachments
                </span><span class="pun">]);</span>
        <span class="pun">}</span>
        <span class="com">// Send MMS messages using all SIMs of all available devices. Messages will be split between all SIMs.</span><span class="pln">
        $msgs </span><span class="pun">=</span><span class="pln"> sendMessages</span><span class="pun">(</span><span class="pln">$mmsMessages</span><span class="pun">,</span><span class="pln"> USE_ALL_SIMS</span><span class="pun">);</span><span class="pln">
        
        print_r</span><span class="pun">(</span><span class="pln">$msgs</span><span class="pun">);</span><span class="pln">
    
        echo </span><span class="str">"Successfully sent bulk messages."</span><span class="pun">;</span>
    <span class="pun">}</span> <span class="kwd">catch</span> <span class="pun">(</span><span class="typ">Exception</span><span class="pln"> $e</span><span class="pun">)</span> <span class="pun">{</span><span class="pln">
        echo $e</span><span class="pun">-></span><span class="pln">getMessage</span><span class="pun">();</span>
    <span class="pun">}</span></pre>
    <pre>

Leave your thought here

Your email address will not be published.