如何使用mysms API向多个手机号码发送短信
Great to hear you've got single-recipient SMS working with the mysms API! Sending to multiple numbers is straightforward—here are two common approaches based on your existing example:
1. Repeat the Single-Recipient Request (Simple & Reliable)
If you're dealing with a small to medium list of recipients, the easiest way is to loop through each number and make a separate API call for each one. This avoids any potential issues with batch parameter formats and works just like your existing request.
For example, if you have two numbers 436761234567 and 436767654321, you'd make these two calls:
https://api.mysms.com/json/message/send?api_key=xxxxx&msisdn=xxx&password=xxx&recipient=436761234567&message=Hi https://api.mysms.com/json/message/send?api_key=xxxxx&msisdn=xxx&password=xxx&recipient=436767654321&message=Hi
In code (using a simple loop in Python, for example):
import requests api_url = "https://api.mysms.com/json/message/send" base_params = { "api_key": "xxxxx", "msisdn": "xxx", "password": "xxx", "message": "Hi" } recipients = ["436761234567", "436767654321"] for number in recipients: request_params = base_params.copy() request_params["recipient"] = number response = requests.get(api_url, params=request_params) # Handle response as needed (check status code, log results, etc.)
2. Use Batch Recipient Parameters (If Supported)
Many SMS APIs allow passing multiple recipients in a single request, either by repeating the recipient parameter or using a comma-separated list. Here are the two likely formats to try (confirm with mysms API docs if you can):
Option A: Repeat the recipient parameter
Append multiple recipient key-value pairs to your URL:
https://api.mysms.com/json/message/send?api_key=xxxxx&msisdn=xxx&password=xxx&recipient=436761234567&recipient=436767654321&message=Hi
Option B: Comma-separated recipients in one recipient parameter
Some APIs accept a comma-separated string of numbers:
https://api.mysms.com/json/message/send?api_key=xxxxx&msisdn=xxx&password=xxx&recipient=436761234567,436767654321&message=Hi
Key Notes to Remember
- All recipient numbers must follow the same format as your single-recipient example (include country code, no spaces or special characters).
- Watch out for mysms API rate limits—if sending to a large list, add small delays between requests to avoid being blocked.
- Test with a tiny set of numbers first to confirm the batch format works for your account.
内容的提问来源于stack exchange,提问作者Ranjit Singh Shekhawat

