Step 1: Building the bot
A couple things to note about building a bot.
- Your bot is going to get called on EVERY email message that is sent to the account.
- Your bot MUST avoid “Returned Mail” loops.
First thing we need to do is set up your file to execute from the system as a script. You do this just as you would a PERL program. Place the shebang on the first line:
#!/usr/local/sbin/php
Next you need to open your stdin (php 4.3 makes the
$stdin
variable a global one so you do not need to fopen
. However I’m running 4.2.1, so I do).
<?php
$stdin = fopen('php://stdin', 'r');
?>
Setup your initial variables. You do not need to create these, but I find that my needs might change for the mailbot so having them available (should I require body parsing, other header information, etc. I don’t have to rewrite anything).
<?php
$message_head = array();
$message_body = "";
?>