Solved

PHP Script to Receive Email

Posted on 2008-06-18
5
1,802 Views
Last Modified: 2013-12-13
Hi,

System Requirement: Windows Server 2003

I need a php script running on this web server to receive emails. Ideally, there would be an email system installed on the web server.

Method 1 (preferred): When an email is received by the email system, a php script is invoked which processes that email.

Method 2: A php script is periodically invoked that checks for email from an email server (local or remote).  

One way or another, I need to receive email with php.

Any tips?

Thanks for your time
0
Comment
Question by:oxygen_728
  • 2
  • 2
5 Comments
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 300 total points
ID: 21816081
There are several mail server which run on mysql. You might be able to use a Sceduled Task to run a php script to either use php pop/imap functions, or tap directly into mysql.

For php mail check functions you can of course also use a non-mysql mailserver and use pop or imap.
0
 

Author Comment

by:oxygen_728
ID: 21816119
Roonan, thanks for the tips.

Do you know a good mail server for a windows server that can invoke a script or executable when an email is received?

Thanks for your time
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 300 total points
ID: 21816156
I'm not an expert on the mailserver world, so can't realy suggest one. I like the setup of the Sceduled Task or Cronjob, as it is mailserver independant which allows my application to shift to another (mail)server more easily, and allow my php server to run from another machine than my mailserver.
0
 

Author Comment

by:oxygen_728
ID: 21816175
Roonan, I understand - my main concern is that I have a larger process of which this is just a small part. So if I have a scheduled task that operates once per minute, then that will slow down the entire system. And I'd be nervous about scheduling the task too fast... with windows being the way it is

0
 

Accepted Solution

by:
kevinx24 earned 200 total points
ID: 21994577
oxygen,

You may be able to do this using a hosted service, Email2HTTP (http://www.email2http.com).

This will allow you to handle mail by simply writing a script that handles a form POST.   Parts of the email would be delivered to your PHP script as form post variables, like $_POST["subject"], $_POST["body"], etc.

See code sample taken from Email2HTTP website:


<?php
 

// Save each attachment from the message to disk

foreach ($_FILES as $attachment)

{

	move_uploaded_file($attachment["tmpname"],

		"../files/" . $attachment["name"]);

}
 

// Send a reply back to the sender by email

// by simply producing some output

$numberOfFiles = sizeof($_FILES);

echo "Thank you, my friend.  I have received your "

	. $numberOfFiles . " files."

	. "\r\n\r\n---Original message---\r\n"

	. $_POST["body"];
 

?>

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now