首页 > 解决方案 > 如何使用 php 以正确的格式发送短信?

问题描述

在这段代码中,我使用短信网关向客户端发送消息。现在,短信发送成功,但格式看起来很简单:

This is a remainder about the title by the 2019-11-11 hello

看起来很简单我想显示的消息应该是这样的:

This is a remainder about the title by 2019-11-11 hello 行应该在about,title和之后date换行message

那么我该怎么做呢?请帮我。

谢谢你

$message = "This is a reminder about the ".$this->input->post("title")." by the ".date("Y-m-d", strtotime($this->input->post("date")))." ".strip_tags(html_entity_decode($this->input->post("notice")))."";
$requestParams = array(
    'user' => '**********',
    'pass' => '**********',
    'sender' => '*******',
    'phone' => trim(json_encode($student_phone, JSON_NUMERIC_CHECK),'[]'),
    'text' => $message,
    'priority' => 'ndnd',
    'stype' => 'normal'
);
$apiUrl = "http://bhashsms.com/api/sendmsg.php?";
foreach($requestParams as $key => $val){
    $apiUrl .= $key.'='.urlencode($val).'&';
}

$apiUrl = rtrim($apiUrl, "&");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$return = json_encode($result);

标签: phphtmlcssmobilesms

解决方案


尝试使用“新行”字符\n。像这样将它插入到字符串中:

$message = "This is a reminder about \n the ".$this->input->post("title")."\n by the ".date("Y-m-d", strtotime($this->input->post("date")))."\n".strip_tags(html_entity_decode($this->input->post("notice")))."";

推荐阅读