简体   繁体   English

如何使用Mailgun解析电子邮件?

[英]How can I parse the email using Mailgun?

by refering this article, I tried to parse the email, but i am failing to do it. 通过引用这篇文章,我试图解析电子邮件,但我没有做到这一点。

I have created free-account on mailgun, created domain, mailbox, etc. I sent one mail from my personal email ID to say, mgtest1@my_domain_name.mailgun.com 我已经在mailgun上创建了免费帐户,创建了域名,邮箱等。我从我的个人电子邮件ID发送了一封邮件,说: mgtest1@my_domain_name.mailgun.com

I have configured the account to forward all mails to "http://project_name/controller_name/action_name" (in case of zend) OR 我已将帐户配置为将所有邮件转发到"http://project_name/controller_name/action_name" (in case of zend)或者

"http://localhost/project_name/file_name.php" (for plain PHP)

It is said that I can access the mail using $_POST (for PHP) , but I am getting blank array. 据说我可以使用$_POST (for PHP)访问邮件,但我得到空白数组。

Where I am going wrong ? 我哪里错了?

I tried with both Zend and plain PHP. 我试过Zend和普通的PHP。 I am simply using print_r($_POST). 我只是使用print_r($ _ POST)。

print_r() is used for printing to the screen. print_r()用于打印到屏幕。 Since the web hook handler is posting to your script, the handler saw the posted data, but you didn't. 由于Web钩子处理程序已发布到您的脚本,因此处理程序会查看已发布的数据,但您没有。 ;) ;)

You should store the data by serializing the array and storing it in a file. 您应该通过序列化数组并将其存储在文件中来存储数据。

<?PHP
$data = serialize($_POST);
$fp = fopen('data.txt', 'w');
fwrite($fp, $data);
fclose($fp);
?>

OR access the data directly: 或直接访问数据:

<?PHP
$data = $_POST['recipient'];
$fp = fopen('data.txt', 'w');
fwrite($fp, $data);
fclose($fp);
?>

Hope that helps! 希望有所帮助! Come chat with us, or send us a ticket, if you still have trouble. 如果您还有问题,请与我们聊天,或发给我们一张票。

Thanks! 谢谢!
Travis S 特拉维斯S.
Mailgun Support Mailgun支持

Mailgun cannot POST messages to localhost. Mailgun无法将消息POST到localhost。 You need to migrate your project to an online server. 您需要将项目迁移到在线服务器。 Right now, the route you have provided is of your localhost server, there is no way for mailgun to access that. 现在,您提供的路由是您的localhost服务器,mailgun无法访问该路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM