The following script was created as a reminder to check my email when on the road. The script is run by a cron job and set to run every hour. If it finds any unread messages in my email it sends me a text message to my phone letting me know there is unread messages in my email.
SCRIPT UPDATE - V2.0
Changes -
Easier and Faster Configure…
Supports Multi-Carriers
All needed headers are set properly - Wasn’t working quit right.
Got rid of the error log - Lack of useful information.
[code]<?php
/*
- Progam: Email Checker
- Purpose:
- Notify user number of unread email
- messages by sending a text message
- to cell phone.
- Programmer: Royce Germain
- Company: eFire Technologies
- Website: http://www.efiretechnologies.com
- Created: 03-29-2007
- Last Modified: 04-13-2007
*/
//***CARRIERS –
$carrier = array(“message.alltel.com”, “vtext.com”, “myboostmobile.com”, “cingularme.com”, “messaging.nextel.com”, “messaging.sprintpcs.com”, “tmomail.net”, “vmobl.com”);
//***SETTING MAIL VARIABLES –
$eol = “rn”;
$who = “Your Name”; //Name on of the owner of the email account
$email_account = "[email protected]"; //Which account to login into - used as the login name as well.
$email_password = “XXXXXX”; //Account password
$phone_number = “5555555555; //Phone number to send text message to
$from_address = "[email protected]”; //Where the email should be coming from
$text_subject = “New Email”; //Subject of text messages
$my_carrier = 1; //Carrier the text message is being sent to.
// Alltel = 0 | Verizon = 1 | Boost Mobile = 2 | Cingular = 3 | Nextel = 4 | Sprint = 5 | T-Mobile = 6 | Virgin Mobile = 7
//====================== DO NOT CHANGE THESE VARIABLES ===============================
$text_body = “”; //FORMATTED LATER
$text_to = $phone_number . “@” . $carrier[$my_carrier];
$who_from = $who . " <" . $from_address . “>” . $eol;
//***SETTING EMAIL HEADER INFORMATION
$text_headers = "From: " . $who_from;
$text_headers .= "Reply-to: " . $who_from;
$text_headers .= “Content-Type: text/plain; charset=iso-8859-1” . $eol;
$text_headers .= “Content-Transfer-Encoding: 8bit” . $eol;
$text_headers .= "X-Sender: " . $who_from;
$text_headers .= “X-Mailer: PHP v” . phpversion() . $eol; //Help avoid spam-filters
$text_headers .= ‘MIME-Version: 1.0’ . $eol;
//===================================================================================
//***MAKE CONNECTION TO MAIL SERVER USING IMAP –
$mailbox = @imap_open("{localhost:143}INBOX", $email_account, $email_password) or die("Couldn’t Open Mail Box: " . imap_last_error());
//***GETTING INFORMATION ABOUT THE MAILBOX –
$mailbox_info = imap_check($mailbox);
$unread_count = 0; //SETTING UNREAD EMAIL COUNT TO ZERO --
//***LOOPING THROUGH ALL THE MESSAGES CURRENTLY IN THE MAILBOX –
for($i = 1; $i <= $mailbox_info->Nmsgs; $i++)
{
$header = imap_header($mailbox,$i); //GETS HEADER INFORMATION FOR SINGLE EMAIL –
if($header->Recent == 'N' || $header->Unseen == 'U' || $header->Unseen == '')
{
$unread_email = $unread_email + 1; //IF THE MESSAGE IS UNSEEN ADD ONE TO UNREAD EMAIL COUNT --
}
}
//***CHECKING FOR IF THERE ANY UNREAD MESSAGES –
$email_s = “email”; //SETTING DEFUALT VALUE - USED IN BODY OF TEXT MESSAGE –
if($unread_email > 0)
{
if($unread_email > 1){ $email_s = "emails"; } //MORE THAN ONE UNREAD EMAIL - CHANGE THE WORD TO EMAILS IN THE TEXT MESSAGE --
$text_body = "You have " . $unread_email . " unread ". $email_s . " in your email account."; //SETTTING BODY OF MESSAGE --
mail($text_to, $text_subject, $text_body, $text_headers, "-f" . $from_address);
}
else
{
}
imap_close($mailbox); //CLOSE IMAP CONNECTION
?>[/code]
USEAGE:
This script is free to use for anyone anywhere. You may delete all top comments and replace with your own information. (But credit is always nice! )
If you have any questions on how to use the functions in this script
please check at http://www.php.net. Below is a list of the functions used.
There are no user defined functions in this script.
– Functions Used –
imap_open()
imap_check()
imap_header()
mail()
You should be able to figure what needs to be changed.
Don’t forget to change the body of the message if you want it more customized.
Tips: imap_open - localhost is correct. That shouldn’t need to be changed.
Furthermore: There is nothing that will be displayed when it is run. No news is good news with this script.
[size=99px]Warning: This has only been tested using Verizon and Alltel carriers. I am not responsible for any misuse of this program. All text charges will still apply![/size]