除非我手动调用脚本,为什么可能发送php邮件但没有收到?

时间:2013-10-13 02:46:29

标签: email twilio php twiml

为什么在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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

类似的东西:

$subject= preg_replace("/[^a-zA-Z0-9]+/", "", $_REQUEST['From']);