So this has probably been done but I have yet to find it so I decided to give it a go...
The Goal: Have a phpBB forum that has threads auto-populated via picture text messages from cell phones.
Prerequisites:
- php_imap is enabled
- ssl is enabled
- phpBB users can set a phone # in their profile, must be unique
The Steps:
1) Snap picture with cell phone. [CHECK]
2) Send to email address. [CHECK]
3) Arrives at email address. [CHECK]
4) PHP Script checks email and lists messages and their attachments [CHECK]
Here's the code for Step 4:
<?php
$mbox = imap_open ("{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX", "EMAILADDRESS@gmail.com", "EMAILPASSWORD")
or die("can't connect: " . imap_last_error());
$headers = imap_headers( $mbox )
or die("Couldn't get emails");
$numEmails = sizeof( $headers );
echo "$numEmails in mailbox.<hr>";
for($i = 1; $i < $numEmails+1; $i++){
$mailHeader = imap_headerinfo($mbox, $i);
$from = $mailHeader->fromaddress;
$subject = strip_tags($mailHeader->subject);
$date = $mailHeader->date;
echo "Email #$i from $from, subject $subject, date $date<br>";
$struct = imap_fetchstructure($mbox, $i);
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($p=2; $p<=$contentParts; $p++) {
$att[$p-2] = imap_bodystruct( $mbox, $i, $p );
}
for ($k=0; $k<sizeof($att); $k++) {
if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$selectBoxDisplay[$k] = $att[$k]->parameters[1]->value;
}
} elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") {
$selectBoxDisplay[$k] = $att[$k]->parameters[0]->value;
}
}
}
if (sizeof($selectBoxDisplay) > 0) {
for ($j=0;$j<sizeof($selectBoxDisplay);$j++) {
echo $selectBoxDisplay[$j] ."<br>";
}
}
}
imap_close( $mbox );
?>
5) Download attachment - no clue how to do this 🙁
6) Create a new thread of the userid who has that phone #
7) Attach downloaded image & insert optional text from text message.
8) If successful, delete IMAP message - if not, maybe log it? Still delete message.
9) Disconnect
I am stuck on Step #5 - I'm at a fundamental lack of knowledge of how attachments and IMAP work. Any help is appreciated 😃