[英]How to Code PHP for Twilio to forward SMS to Email
Coding newby here.在这里编码 newby。
I am trying to write some PHP code to enable SMS forwarding to email with a Twilio phone number.我正在尝试编写一些 PHP 代码,以便使用 Twilio 电话号码将 SMS 转发到 email。 Unfortunately, I haven't had any success in doing so.不幸的是,我这样做没有任何成功。
I saw some tutorials using SendGrid, but I would rather use my own PHP code on my web server.我看到了一些使用 SendGrid 的教程,但我宁愿在我的 web 服务器上使用我自己的 PHP 代码。
Can anyone point me to a good source or if possible, provide step by step instructions?谁能给我指出一个好的来源,或者如果可能的话,提供分步说明吗?
Thank you谢谢
Twilio developer evangelist here. Twilio 开发人员布道师在这里。
There is a "forward SMS to email" quick deploy here where you don't need a server--Twilio will host it for you!这里有一个“将 SMS 转发到电子邮件”的快速部署,您不需要服务器——Twilio 将为您托管它!
This is how you could do it with PHP : 这就是您可以使用 PHP 做到这一点的方法:
<?php
/**
* This section ensures that Twilio gets a response.
*/
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response></Response>'; //Place the desired response (if any) here
/**
* This section actually sends the email.
*/
/* Your email address */
$to = "your-email@example.com";
$subject = "Message from {$_REQUEST['From']} at {$_REQUEST['To']}";
$message = "You have received a message from {$_REQUEST['From']}. Body: {$_REQUEST['Body']}";
$headers = "From: webmaster@example.com"; // Who should it come from?
mail($to, $subject, $message, $headers);
To make that code above work,为了使上面的代码工作,
From
and To
email addresses.修改以下代码以更新From
和To
email 地址。If you're a Node.js person, here is a tutorial that uses Twilio Functions , Twilio's serverless environment for hosting web (Node) apps.如果您是 Node.js 人,这里有一个使用Twilio 函数的教程,Twilio 的无服务器环境用于托管 web(节点)应用程序。
Let me know if this helps at all!让我知道这是否有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.