Reputation: 837
How can I add and Send SMS to number dynamically by PHP code.
I have add number from admin panel and send SMS to this static number. It works, but if I want to add number from HTML form. So how can I register number dynamically by PHP code.
$message = $client->messages->create(
'+919711969920', // Text this number
array(
'from' => '(205) 358-4782', // From a valid Twilio number
'body' => "Hello Sudhir"
)
);
Upvotes: 0
Views: 555
Reputation: 73100
Twilio developer evangelist here.
You can absolutely take input from an HTML form. Rather than hard coding the number into your PHP you would need to retrieve the number you want to send the message to from the incoming request parameters.
You could do this with:
$message = $client->messages->create(
$_REQUEST["to"],
array(
'from' => '(205) 358-4782', // From a valid Twilio number
'body' => "Hello Sudhir"
)
);
Make sure your form then has an input field with the name "to" and when you submit the form you will be able to get the parameter from the request with the code above.
<input type="tel" name="to" id="to" />
Let me know if that helps at all.
Upvotes: 1