我正在使用发条api。错误代码为:Message failed - Error: Invalid 'To' Parameter
我认为这是在$ message行中。我没有正确设置变量。
<?php
require 'class-Clockwork.php';
try
{
// Create a Clockwork object using your API key
$API_KEY = "API_KEY";
$clockwork = new Clockwork( $API_KEY );
$phonenumber = $_POST['phonenumber'];
$message = $_POST['sendmessage'];
// Setup and send a message
$message = array( 'to' => '$phonenumber', 'message' => '$sendmessage' );
$result = $clockwork->send( $message );
// Check if the send was successful
if($result['success']) {
echo 'Message sent - ID: ' . $result['id'];
} else {
echo 'Message failed - Error: ' . $result['error_message'];
}
}
catch (ClockworkException $e)
{
echo 'Exception sending SMS: ' . $e->getMessage();
}
?>
答案 0 :(得分:0)
$message = array( 'to' => '$phonenumber', 'message' => '$sendmessage' );
这应该是
$message = array( 'to' => $phonenumber, 'message' => $sendmessage );
否则,您将获得文字文本"$phonenumber"
,而不是变量的内容。