Issue
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"
)
);
Solution
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.
Answered By - philnash Answer Checked By - Marilyn (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.