Answers.Body: <p>Hi I'm having this exact problem and have done some debugging:</p>
  
  <p>When making a new SMS there are three steps</p>
  
  <ol>
  <li>you first select recipients</li>
  <li>then you write the body of the SMS</li>
  <li>you schedule the SMS</li>
  </ol>
  
  <p>Between step one and two the table <code>civicrm_mailing_recipients</code> correctly gets filled with email_id set to null and phone_id set with the id of the contacts' phone numbers. This gets done in the function <code>getRecipients</code> in <code>CRM/Mailing/BAO/Mailing.php</code>, and the phone_ids get set because <code>$mode</code> is set to "sms".</p>
  
  <p>But after completing step three this function is called again and <code>$mode</code> is now empty, and the email_id is set instead and phone_id is set to null.</p>
  
  <p>This results in an empty result from an sql-call in the function <code>deliver</code> in <code>CRM/Mailing/Bao/MailingJob.php</code>, which try to get the recipients, but returns empty and thus there's no one to send to.</p>
  
  <p>This second call to <code>getRecipients</code> is made by the function <code>create</code>, also in <code>CRM/Mailing/BAO/Mailing.php</code>, and it's there $mode is NOT getting set, and there's no checking if it's an sms or not:</p>
  
  <pre><code>  // Populate the recipients.
    if (empty($params['_skip_evil_bao_auto_recipients_'])) {
      self::getRecipients($job-&gt;id, $mailing-&gt;id, NULL, NULL, TRUE, $mailing-&gt;dedupe_email);
    }
  </code></pre>
  
  <p>So to fix that I altered it to this:</p>
  
  <pre><code>  // Populate the recipients.
    if (empty($params['_skip_evil_bao_auto_recipients_'])) {
      // check if it's an sms
      $mode = $mailing-&gt;sms_provider_id ? 'sms' : NULL;
      self::getRecipients($job-&gt;id, $mailing-&gt;id, NULL, NULL, TRUE, $mailing-&gt;dedupe_email, $mode);
    }
  </code></pre>
  
  <p>And now it works. When the "Send Scheduled SMS"-job is run, the bulk sms gets sent.
  I've filed an issue at <a href="https://issues.civicrm.org/jira/browse/CRM-17331" rel="nofollow">https://issues.civicrm.org/jira/browse/CRM-17331</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-30T08:28:59.637Z
Answers.Text: Just a heads up: The issue has been fixed for 4.7 https://github.com/civicrm/civicrm-core/pull/7062
Answers.UserDisplayName: Anders Iversen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-01T17:26:53.883Z
Answers.Text: And I can verify that bulk SMS works in 4.7.12 as I had this problem also
Answers.UserDisplayName: Andy Clark
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-08T10:22:20.807Z
Answers.Text: This code change fixed the issue for me on 4.6.24 . I've submitted a PR for 4.6: https://github.com/civicrm/civicrm-core/pull/10308
Answers.UserDisplayName: davejenx
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-02T14:22:38.317Z
Answers.LastActivityDate: 2015-10-03T14:57:02.577Z
Answers.LastEditDate: 2015-10-03T14:57:02.577Z
Answers.UserDisplayName: Anders Iversen
Answers.Body: <p>It is because you have a test account.  If you go to a paid account, the issue will stop.</p>
  
  <p><a href="https://www.twilio.com/blog/2012/07/new-twilio-free-trial-phone-numbers-for-all.html" rel="nofollow noreferrer">https://www.twilio.com/blog/2012/07/new-twilio-free-trial-phone-numbers-for-all.html</a></p>
  
  <blockquote>
    <p>SMS</p>
  
  <pre><code>You must verify a phone number before you can send SMS messages
  to it from your trial phone number.
  </code></pre>
  </blockquote>
  
  <p><a href="https://www.twilio.com/help/faq/twilio-basics/how-does-twilios-free-trial-work" rel="nofollow noreferrer">https://www.twilio.com/help/faq/twilio-basics/how-does-twilios-free-trial-work</a></p>
  
  <blockquote>
    <p>Trial numbers can only call and text verified numbers.</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/a/25581823/4406810">https://stackoverflow.com/a/25581823/4406810</a></p>
  
  <blockquote>
    <p>2) Is it because I have a trial account and will it work once I
    upgrade? From an trial account You can send SMS to the number with you
    registered. To other numbers it will work after you upgrade your
    account.</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-09T22:45:22.280Z
Answers.Text: The phone is verified. It's my own phone. I can open my profile and send myself an sms from the actions menu. I'm afraid that is not the problem.  It the phone wasn't verified it would not allow individual messages either. And it does. The problem is in the bulk-sms.
Answers.UserDisplayName: user2329051
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-09T23:57:07.497Z
Answers.Text: So you can send individual SMS to numbers/contacts other than yourself? When I first had a test account, I could only send to my mobile, not other contacts. When I got a paid account, I was then able to send to other mobile numbers.
Answers.UserDisplayName: Allen Hutchison
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T04:02:57.840Z
Answers.Text: Yes I can. I've contacted them previously, verified each number and now I can send them SMS. If that were the problem Twilio API would have logged the petition and shown the error, but they don't even receive anything if I try to send a bulk-sms. Let's see if someone has as another idea but I really appreciate that you are trying to help. Thanks :).
Answers.UserDisplayName: user2329051
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T05:05:38.317Z
Answers.Text: You bet!  Hope you can sort it out soon.
Answers.UserDisplayName: Allen Hutchison
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-09T22:21:37.000Z
Answers.LastActivityDate: 2015-04-09T22:21:37.000Z
Answers.LastEditDate: 2017-05-23T12:38:59.763Z
Answers.UserDisplayName: Allen Hutchison
Answers.Body: <p>I experienced this myself, but understood that it was plenty of ways to run into the issue of not being able to send bulk-sms. Try to limit the issue first:</p>
  
  <p>If it is in fact the same issue as I experienced, on the forum thread, then this will help you figure out what the issue is all about.</p>
  
  <ol>
  <li><p>Send a bulk sms with a template including a token, and an e-Mail adress recorded at the contact.</p></li>
  <li><p>Send a bulk sms with a template without any tokens, and an e-Mail adress recorded at the contact.</p></li>
  <li><p>Send a bulk sms with a template including a token, and no e-Mail adress recorded at the contact.</p></li>
  <li><p>Send a bulk sms with a template without any tokens, and no e-Mail adress recorded at the contact.</p>
  
  <ol start="5">
  <li>And then possibly combinations where "No bulk e-mail" is ticked off.</li>
  </ol></li>
  </ol>
  
  <p>There was submitted a fix for case 5 I think, but our issue actually was case 1, I think.</p>
  
  <p>Good luck!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T17:08:32.937Z
Answers.Text: Well the good thing is that I can give you a quick response for all of the tests. None of them worked. :(
Answers.UserDisplayName: user2329051
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T17:53:40.220Z
Answers.Text: @user2329051 Ok, then I suspect that the issue is different from those I experienced...
Answers.UserDisplayName: Flying
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T18:00:22.547Z
Answers.Text: @user2329051 just another thought... As I discovered, bulk sms is developed on the basis of the code of bulk mail. So in some cases they share both code and settings... Can you send bulk mail without any issues? The settings of CiviMail is sometimes influencing bulk sms. Maybe you should check your CiviMail settings as well? (Just a longshot, so take it for what it is worth)
Answers.UserDisplayName: Flying
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T23:43:18.443Z
Answers.Text: Just checked: bulk email goes through but not bulk SMS...
Answers.UserDisplayName: user2329051
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T09:12:45.557Z
Answers.LastActivityDate: 2015-04-10T09:12:45.557Z
Answers.UserDisplayName: Flying
Body: <p>I'm working for Engineers Without Borders Galicia and we are migrating our volunteer managing system to CiviCRM. 
  I'm experiencing something quite like this bug:
  <a href="https://issues.civicrm.org/jira/browse/CRM-15702">https://issues.civicrm.org/jira/browse/CRM-15702</a></p>
  
  <p>I can send SMS to individuals from his profile page, but bulk SMS are not sent , although the report says the job is completed. The users in the group (a one man group) have all emails. Our SMS provider is Twilio and there is no trace of the bulk sms. The normal ones get perfectly sent (and logged).</p>
  
  <p>Any help would be very much appreciated.</p>
  
  <p>Iván Lago.</p>
  
  <p>IT Engineer at Engineers Without Borders Galicia</p>
  
  <p>More info: 
  Server version: Apache/2.2.22 (Debian)
  CMS:            Drupal 7.36
  CiviCRM version:4.6.0
  PHP:            5.4.39-0+deb7u2
  MySQL:          5.5.41-0+wheezy1
  SMS Provider:   Twilio (test acount)</p>
  
  <p>//Edit 1: As someone noticed at CiviCRM forums, there's no such version 5.6.0 . It was a typo fail that I've copy-pasted many times. Sorry about that. <strong>CiviCRM version is 4.6.0.</strong></p>
  
  <p>//Edit 2: To give more data, I'm forcing the process of sending pending sms with the call:</p>
  
  <blockquote>
    <p>php /var/www/sites/all/modules/civicrm/bin/cli.php -u [myuser] -p
    [mypassword] -e Job -a execute</p>
  </blockquote>
  
  <p>Obviously, with my user and password where necessary. The jobs get done... but no sms are ever sent :( . </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-19T08:51:32.010Z
Comments.Text: I am having the same issue. I can send SMS messages to an individual but cannnot send bulk SMS messages' I get a SQL syntax error as shown in the backtrace below. $backTrace = #0 /var/www/test/sites/all/modules/civicrm/CRM/Core/Error.php(912): CRM_Core_Error::backtrace("backTrace", TRUE) #1 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error)) #2 /var/www/test/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error)) #3 /var/www/test/sites/all/modules/civicrm/packages/DB.php(976): PEAR_Error->PEAR_Error("DB Error: syntax error", -2, 16, (
Comments.UserDisplayName: Martin Fuggle
Tags: <civimail><drupal><4.6.0>
Title: Why can't I send bulk SMS (even though I can send individually)?
ThreadText: # Why can't I send bulk SMS (even though I can send individually)?
  
  (Asked by: username_0 on 2015-04-09)
  
  I'm working for Engineers Without Borders Galicia and we are migrating our volunteer managing system to CiviCRM.
  I'm experiencing something quite like this bug:
  <https://issues.civicrm.org/jira/browse/CRM-15702>
  
  I can send SMS to individuals from his profile page, but bulk SMS are not sent , although the report says the job is completed. The users in the group (a one man group) have all emails. Our SMS provider is Twilio and there is no trace of the bulk sms. The normal ones get perfectly sent (and logged).
  
  Any help would be very much appreciated.
  
  Iván Lago.
  
  IT Engineer at Engineers Without Borders Galicia
  
  More info:
  Server version: Apache/2.2.22 (Debian)
  CMS: Drupal 7.36
  CiviCRM version:4.6.0
  PHP: 5.4.39-0+deb7u2
  MySQL: 5.5.41-0+wheezy1
  SMS Provider: Twilio (test acount)
  
  //Edit 1: As someone noticed at CiviCRM forums, there's no such version 5.6.0 . It was a typo fail that I've copy-pasted many times. Sorry about that. **CiviCRM version is 4.6.0.**
  
  //Edit 2: To give more data, I'm forcing the process of sending pending sms with the call:
  
  > php /var/www/sites/all/modules/civicrm/bin/cli.php -u [myuser] -p
  > [mypassword] -e Job -a execute
  
  Obviously, with my user and password where necessary. The jobs get done... but no sms are ever sent :( .
  
  **Tags:** civimail, drupal, 4.6.0
  
  > **Comments:**
  > **username_1**: I am having the same issue. I can send SMS messages to an individual but cannnot send bulk SMS messages' I get a SQL syntax error as shown in the backtrace below. $backTrace = #0 /var/www/test/sites/all/modules/civicrm/CRM/Core/Error.php(912): CRM_Core_Error::backtrace("backTrace", TRUE) #1 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error)) #2 /var/www/test/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error)) #3 /var/www/test/sites/all/modules/civicrm/packages/DB.php(976): PEAR_Error->PEAR_Error("DB Error: syntax error", -2, 16, (  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2015-10-02. Score: 5
  
  Hi I'm having this exact problem and have done some debugging:
  When making a new SMS there are three steps
  
  you first select recipients
  then you write the body of the SMS
  you schedule the SMS
  
  Between step one and two the table civicrm_mailing_recipients correctly gets filled with email_id set to null and phone_id set with the id of the contacts' phone numbers. This gets done in the function getRecipients in CRM/Mailing/BAO/Mailing.php, and the phone_ids get set because $mode is set to "sms".
  But after completing step three this function is called again and $mode is now empty, and the email_id is set instead and phone_id is set to null.
  This results in an empty result from an sql-call in the function deliver in CRM/Mailing/Bao/MailingJob.php, which try to get the recipients, but returns empty and thus there's no one to send to.
  This second call to getRecipients is made by the function create, also in CRM/Mailing/BAO/Mailing.php, and it's there $mode is NOT getting set, and there's no checking if it's an sms or not:
    // Populate the recipients.
    if (empty($params['_skip_evil_bao_auto_recipients_'])) {
      self::getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, $mailing->dedupe_email);
    }
  
  So to fix that I altered it to this:
    // Populate the recipients.
    if (empty($params['_skip_evil_bao_auto_recipients_'])) {
      // check if it's an sms
      $mode = $mailing->sms_provider_id ? 'sms' : NULL;
      self::getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, $mailing->dedupe_email, $mode);
    }
  
  And now it works. When the "Send Scheduled SMS"-job is run, the bulk sms gets sent.
  I've filed an issue at https://issues.civicrm.org/jira/browse/CRM-17331
  
  > **Comments:**
  > **username_2**: Just a heads up: The issue has been fixed for 4.7 https://github.com/civicrm/civicrm-core/pull/7062  
  > **username_3**: And I can verify that bulk SMS works in 4.7.12 as I had this problem also  
  > **username_4**: This code change fixed the issue for me on 4.6.24 . I've submitted a PR for 4.6: https://github.com/civicrm/civicrm-core/pull/10308  
  
  ---
  
  ### Answer by username_5 on 2015-04-09. Score: 3
  
  It is because you have a test account.  If you go to a paid account, the issue will stop.
  https://www.twilio.com/blog/2012/07/new-twilio-free-trial-phone-numbers-for-all.html
  
  SMS
  You must verify a phone number before you can send SMS messages
  to it from your trial phone number.
  
  
  https://www.twilio.com/help/faq/twilio-basics/how-does-twilios-free-trial-work
  
  Trial numbers can only call and text verified numbers.
  
  https://stackoverflow.com/a/25581823/4406810
  
  2) Is it because I have a trial account and will it work once I
    upgrade? From an trial account You can send SMS to the number with you
    registered. To other numbers it will work after you upgrade your
    account.
  
  > **Comments:**
  > **username_0**: The phone is verified. It's my own phone. I can open my profile and send myself an sms from the actions menu. I'm afraid that is not the problem.  It the phone wasn't verified it would not allow individual messages either. And it does. The problem is in the bulk-sms.  
  > **username_5**: So you can send individual SMS to numbers/contacts other than yourself? When I first had a test account, I could only send to my mobile, not other contacts. When I got a paid account, I was then able to send to other mobile numbers.  
  > **username_0**: Yes I can. I've contacted them previously, verified each number and now I can send them SMS. If that were the problem Twilio API would have logged the petition and shown the error, but they don't even receive anything if I try to send a bulk-sms. Let's see if someone has as another idea but I really appreciate that you are trying to help. Thanks :).  
  > **username_5**: You bet!  Hope you can sort it out soon.  
  
  ---
  
  ### Answer by username_6 on 2015-04-10. Score: 1
  
  I experienced this myself, but understood that it was plenty of ways to run into the issue of not being able to send bulk-sms. Try to limit the issue first:
  
  If it is in fact the same issue as I experienced, on the forum thread, then this will help you figure out what the issue is all about.
  
  1. Send a bulk sms with a template including a token, and an e-Mail adress recorded at the contact.
  2. Send a bulk sms with a template without any tokens, and an e-Mail adress recorded at the contact.
  3. Send a bulk sms with a template including a token, and no e-Mail adress recorded at the contact.
  4. Send a bulk sms with a template without any tokens, and no e-Mail adress recorded at the contact.
  
     5. And then possibly combinations where "No bulk e-mail" is ticked off.
  
  There was submitted a fix for case 5 I think, but our issue actually was case 1, I think.
  
  Good luck!
  
  > **Comments:**
  > **username_0**: Well the good thing is that I can give you a quick response for all of the tests. None of them worked. :(  
  > **username_6**: @username_0 Ok, then I suspect that the issue is different from those I experienced...  
  > **username_6**: @username_0 just another thought... As I discovered, bulk sms is developed on the basis of the code of bulk mail. So in some cases they share both code and settings... Can you send bulk mail without any issues? The settings of CiviMail is sometimes influencing bulk sms. Maybe you should check your CiviMail settings as well? (Just a longshot, so take it for what it is worth)  
  > **username_0**: Just checked: bulk email goes through but not bulk SMS...  
  
  ---
  
  