我已经通过cPanel将传入的电子邮件重定向到下面的php脚本。目前它只是发送电子邮件回复,所以我可以测试我有正确的信息,一旦我确认我将开始添加到数据库。
我需要知道的是如何使用codeigniter来执行此操作?
另外,我会在哪里将电子邮件重定向到cPanel,例如在他们去的时候 - public_html / email / parse.php,我如何将它们重定向到codeigniter中的控制器?
我已尝试将此代码放入控制器,但电子邮件会反弹。
#!/usr/bin/php -q
<?php
// get contents of email and add to $email
$email = file_get_contents('php://stdin');
// regular expression to get parts of email that I need
preg_match_all("/(To):\s(.*)\n/i", $email, $to);
preg_match_all("/(Subject):\s(.*)\n/i", $email, $subject);
preg_match_all("/(From):\s(.*)\n/i", $email, $from);
// assign parts of email to variables
$sender = $to[2][0];
$sender = trim($sender, ' " ');
$sender_id = explode('@', $sender);
$sender_id = $sender_id[0];
$subject = $subject[2][0];
$from = $from[2][0];
// make a reply email to test the above works
$reply = "Here's your information!\n\nSender: $sender\nSender ID: $sender_id\nFrom: $from\nSubject: $subject";
// send email to test
mail($from, 'From my email pipe!', $reply, 'From:noreply@mydomain.me');
?>