为什么在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>
我只是检查 php mail 函数中每个变量的内容,当 twilio 调用脚本以查看实时 twilio 消息中是否存在字符时。结果是这样的:
$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
我尝试从主题中删除"+"但没有成功,但是当我从主题中删除整个电话号码时,它以各种方式工作。电子邮件和文本会适当地传递。这对我来说毫无意义。也许它的教父虚拟主机再次扰乱了我的生活。
也许 from 字符串有破坏 mail(( 调用的坏字符,但可以透明地回显。尝试在将字符串放入 mail(( 之前清理字符串。
像这样:
$subject= preg_replace("/[^a-zA-Z0-9]+/", "", $_REQUEST['From']);