0

为什么在 twilio 调用页面的第二种情况下可能不会收到 php 邮件?是否有可能从 api 返回的字符导致电子邮件无法送达?

1) 如果我在浏览器中输入 URL,它会尝试在我的录音文件夹中制作一个 wav 文件,然后我会收到所有收件人的电子邮件和短信。提供以下输出,“1”表示消息已发送。

2)如果twilio调用页面并处理xml,实际消息被记录到我的服务器,下面的输出被提供给twilio(我已经在我的帐户中验证过),但没有人收到电子邮件或文本。再见后xml的正文仍然显示“1”,表示消息已发送。

我的脚本:

<?php
date_default_timezone_set('America/New_York');
//copy the remote wav file to my server
$recording = file_get_contents($_REQUEST['RecordingUrl']);
$name = "recordings/".str_replace("+","",$_REQUEST['Caller'])."-".date('Y-m-d-G-i-s',time()).".wav";
$fh = fopen("../".$name, 'w') or die("can't open file");
$stringData = $recording;
fwrite($fh, $stringData);
fclose($fh);

//email the people that need to get the message
$to = "email1@yahoo.com";
$subject = "Voicemail from ".$_REQUEST['From'];
$message = "Click below to listen to your message:\n\r  http://domain.com/twilio/".$name;
$from = "email2@domain.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
$to = "email3@domain.com";
mail($to,$subject,$message,$headers);
$to = "9545555555@messaging.sprintpcs.com";
$sent = mail($to,$subject,$message,$headers);

header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
            <Response>
                <Say>Thank you for your message. Good bye.".$sent."</Say>
                <Hangup/>
            </Response>";
?>

输出:

        <Response>
            <Say>Thank you for your message. Good bye.1</Say>
            <Hangup/>
        </Response>

当 twilio 调用脚本以查看实时 twilio 消息中是否存在字符时,我只是检查 php 邮件函数中每个变量的内容。结果是这样的:

$to = 9545555555@messaging.sprintpcs.com
$subject = Voicemail from +19545555555

$message = Click below to listen to your message:

  http://domain.com/twilio/recordings/19545555555-2013-10-12-22-57-03.wav

$headers = From:email2@domain.com

如果我在浏览器中手动调用脚本,它们是:

$to = 9545555555@messaging.sprintpcs.com
$subject = Voicemail from 
$message = Click below to listen to your message:

  http://domain.com/twilio/recordings/-2013-10-12-23-04-37.wav

From:email2@domain.com
4

2 回答 2

0

也许 from 字符串有坏字符会破坏 mail() 调用,但会透明地回显。在将它放入 mail() 之前尝试清理你的字符串。

就像是:

$subject= preg_replace("/[^a-zA-Z0-9]+/", "", $_REQUEST['From']);
于 2013-10-16T01:17:08.850 回答
0

我尝试从主题中删除“+”但没有成功,但是当我从主题中删除整个电话号码时,它会以各种方式工作。电子邮件和文本传递得当。对我来说完全是无稽之谈。也许它的godaddy虚拟主机再次扰乱了我的生活。

于 2013-10-13T03:20:24.750 回答