Can I have Webserver for sensor data and send e-mail via PHP GET?

I have an Arduino Uno with Ethernet Shield. I currently have it programmed to control my Chicken Coop. It looks at various sensors and controls door and relays based on inputs. It also publishes all this to webpage, via Arduino WebServer, for me to see data and status of various items. That all works GREAT, the problem is I want to send e-mail on certain events, Temp too Low, Water or food too low, Ect.... I have a remote server ( www.hscfire.com ) that I have an e-mail script sitting on that all it requires is to call a URL Ex: "www.hscfire.com/script/arduino.php?Message= put in message info here" . What I want is to call this script based on certain things happening and put various data points, ex.- temps, door status, fan status, in the Message= Section! I have searched everywhere and can find examples that will send e-mails via PHP or host webpage like I'm currently doing but not BOTH at the same time? Any and all help is greatly appreciated.

Thanks,

Chris
Malvern, Arkansas

My Current Code: Kinda long and could probably be cleaned up a little but I'm still new and learning.

Had to remove some code at various points - //**********************************Removed Stuff
Mainly In/out setup and web display of raw in/out status stuff


/*
 
 
 // Load various Libraries
#include <OneWire.h> //One Wire Sensors
#include <DallasTemperature.h> //Dallas Temp Sensors
#include <SPI.h> // ??
#include <Ethernet.h> //Ethernet Shield

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,200); //IP address for Webserver


// Initialize the Ethernet server library
// with the IP address and port you want to use 
EthernetServer server(83);

//**********************************Removed Stuff

void setup() {

// Open serial communications and wait for port to open:
  Serial.begin(9600);
   Serial.println("Gaines' Arduino Chicken Coop Controler!");
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
    
// Start up the Sensor library
  sensors.begin();
    Serial.println( "Sensors started!" );
  }


// start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());


  //**********************************Removed Stuff
}


void loop() {
  
  
  
// Read and store the value of various analog & digital sensors
  
  //**********************************Removed Stuff

 //Rain Barrel Level - OK LED Control
 
   if (OK2Pump <= 100) {     // If rain barrel has enough water to pump
    // turn Rain Barrel LED on:    
      digitalWrite(rainBarrel, HIGH);
    
    } 
    else {  // turn Rain Barrel LED OFF:
      digitalWrite(rainBarrel, LOW);
[b]Would like to send e-mail HERE![/b]
       }
   
//Vent Fan Control  
 // Turn off the Vent fan outlet when the Walk Door is open, 
 //   or if Inside Temp gets above insideTempVent Setting at top of code above Setup.
  
   if (walkdoorState == LOW && insideTemperature >= insideTempVent) { 
    // If Walk  Through Door is CLOSED & Inside Temp is over insideTempVent Setting
    // turn Vent Fan On:    
      digitalWrite(ventFan, LOW);
                    
    } 
    else {  // turn Vent Fan OFF:
      digitalWrite(ventFan, HIGH); }

//**********************************Removed Stuff
 /*
*********************************************************************
*/   
   
 //ETHERNET Stuff
  // listen for incoming clients
  EthernetClient client = server.available();
  
  if (client) 
    Serial.println("New client on WebPage!!");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
       if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
		  client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 10");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>"); //Set HTML
          //Sets Heading
          client.println("<head> <title> Gaines Family Farm Coop </title> </head>"); // Change Heading in Title Bar of Browser
          client.println("<body bgcolor=AliceBlue>"); 
          
       // Title Line!
             client.print("<b>Gaines' ARDUINO Chicken Coop WebServer"); client.println("
");
             client.print("<hr>") ;  //Print Horizontal Line on Webpage 
             client.println("
"); //Enter Blank Line after title
            
 //Analog Input Readings            
         //**********************************Removed Stuff
		
//Print Various Sensor & Output Status'

//Chicken Door Status
        if (chickendoorState <= 100) {     // if Check Door input is under 100 Door is Open
		// Print Chicken Door is Open:    
		client.print("Chicken Door is <b>OPEN</b>") ;
        }	 
	
		else if (chickendoorState >= 900) {  // If  Chicken Door input is over 900, door is closed.
		client.print("Chicken Door is CLOSED") ;} 
       
		else {  // If not Open or Closed 
		client.print("<b>Chicken Door Status is UNKNOWN!!</b>") ;
[b]Would like to send email HERE[/b]
		} 
	   
		client.println("
"); client.println("
");


//**********************************Removed Stuff

//Rain Barrel Status
        if (OK2Pump <= 150) {     // If rain barrel has enough water to pump
    // Print Rain Barrel is OK in BLUE Font:    
      client.print("Rain Barrel Level is OK") ;
    
    } 
    else {  // If not Print Rain Barrel Level is LOW! in RED Font:
       client.print("<b><strong><font color=#DF0101>Rain Barrel Level is LOW!!!</font></b></strong>") ;} 
       client.println("
"); client.println("
");
        
//**********************************Removed Stuff
 
  client.print("<hr>") ;  //Print Horizontal Line on Webpage 
  client.println("
");  // Blank Line      
                   
 //TEMPERATURE AREA!!
     //Print Inside Temperature  
     client.print("<b>Coop Inside Temperature is: ");
     client.print(insideTemperature);
     client.print(" deg."); client.println("
");
     client.println("
");

     //Print Outside Temperature
     client.print("Coop Outside Temperature is: ");
     client.print(outsideTemperature);
     client.print(" deg.</b>");client.println("
");
     client.println("
");
           
      client.print("<hr>") ;  //Print Horizontal Line on Webpage 
      client.println("
");  // Blank Line   
      
  

// End HTML           
      client.println("</html>");
      break;
        }  // Closes if C = current line blank
        
         
         
       if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }  
        
       
  //  Closer for Ethernat Stuff     
        } // Closes "if Client Avaliable" Line
      
    } // Closes While Client
  
   // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
    
} //Loop Closer

zoomkat regularly posts code that has the Arduino being a server and a client.

My Arduino system at http://www.2wg.co.nz sends push emails directly to my iPhone whenever anything important is happening.

I use my own email implementation with is just a reworking of existing email code for Arduino that is readily available.

I email using an SMTP port 25 connection to my ISP. Since my ISP knows my IP address I don't even have to log in to their email server.

Cheers

Catweazle NZ

Combined client/server code that might be modified to do what you need. The client portion could be modified to send a get request to a server running PHP, or could be modified to send email via your ISP's SMTP server.

//zoomkat 7-03-12, combined client and server
//simple button GET with iframe code
//for use with IDE 1.0
//open serial monitor and send an g to test client and
//see what the arduino client/server receives
//web page buttons make pins high/low
//use the ' in html instead of " to prevent having to escape the "
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //assign arduino mac address
byte ip[] = {192, 168, 1, 102 }; // ip in lan assigned to arduino
byte gateway[] = {192, 168, 1, 1 }; // internet access via router
byte subnet[] = {255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port arduino server will use
EthernetClient client;
char serverName[] = "web.comporium.net"; // (DNS) zoomkat's test web page server
//byte serverName[] = { 208, 104, 2, 86 }; // (IP) zoomkat web page server IP address

String readString; //used by server to capture GET request 

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  pinMode(6, OUTPUT); //pin selected to control
  pinMode(7, OUTPUT); //pin selected to control
  pinMode(8, OUTPUT); //pin selected to control

  //pinMode(5, OUTPUT); //pin 5 selected to control
  Ethernet.begin(mac,ip,gateway,gateway,subnet); 
  server.begin();
  Serial.begin(9600); 
  Serial.println(F("server/client 1.0 test 7/03/12")); // keep track of what is loaded
  Serial.println(F("Send an g in serial monitor to test client")); // what to do to test client
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) 
  {
    byte inChar;
    inChar = Serial.read();
    if(inChar == 'g')
    {
      sendGET(); // call client sendGET function
    }
  }  

  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.print(readString); //print to serial monitor for debuging 

            //now output HTML data header
          if(readString.indexOf('?') >=0) { //don't send new page
            client.println(F("HTTP/1.1 204 Zoomkat"));
            client.println();
            client.println();  
          }
          else {   
            client.println(F("HTTP/1.1 200 OK")); //send new page on browser request
            client.println(F("Content-Type: text/html"));
            client.println();

            client.println(F("<HTML>"));
            client.println(F("<HEAD>"));
            client.println(F("<TITLE>Arduino GET test page</TITLE>"));
            client.println(F("</HEAD>"));
            client.println(F("<BODY>"));

            client.println(F("<H1>Zoomkat's simple Arduino 1.0 button</H1>"));

            // DIY buttons
            client.println(F("Pin5"));
            client.println(F("<a href=/?on2 target=inlineframe>ON</a>")); 
            client.println(F("<a href=/?off3 target=inlineframe>OFF</a>

")); 

            client.println(F("Pin6"));
            client.println(F("<a href=/?on4 target=inlineframe>ON</a>")); 
            client.println(F("<a href=/?off5 target=inlineframe>OFF</a>

")); 

            client.println(F("Pin7"));
            client.println(F("<a href=/?on6 target=inlineframe>ON</a>")); 
            client.println(F("<a href=/?off7 target=inlineframe>OFF</a>

")); 

            client.println(F("Pin8"));
            client.println(F("<a href=/?on8 target=inlineframe>ON</a>")); 
            client.println(F("<a href=/?off9 target=inlineframe>OFF</a>

")); 

            client.println(F("Pins"));
            client.println(F("&nbsp;<a href=/?off2468 target=inlineframe>ALL ON</a>")); 
            client.println(F("&nbsp;<a href=/?off3579 target=inlineframe>ALL OFF</a>")); 

            client.println(F("<IFRAME name=inlineframe style='display:none'>"));          
            client.println(F("</IFRAME>"));

            client.println(F("</BODY>"));
            client.println(F("</HTML>"));
          }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf('2') >0)//checks for 2
          {
            digitalWrite(5, HIGH);    // set pin 5 high
            Serial.println(F("Led 5 On"));
            Serial.println();
          }
          if(readString.indexOf('3') >0)//checks for 3
          {
            digitalWrite(5, LOW);    // set pin 5 low
            Serial.println(F("Led 5 Off"));
            Serial.println();
          }
          if(readString.indexOf('4') >0)//checks for 4
          {
            digitalWrite(6, HIGH);    // set pin 6 high
            Serial.println(F("Led 6 On"));
            Serial.println();
          }
          if(readString.indexOf('5') >0)//checks for 5
          {
            digitalWrite(6, LOW);    // set pin 6 low
            Serial.println(F("Led 6 Off"));
            Serial.println();
          }
          if(readString.indexOf('6') >0)//checks for 6
          {
            digitalWrite(7, HIGH);    // set pin 7 high
            Serial.println(F("Led 7 On"));
            Serial.println();
          }
          if(readString.indexOf('7') >0)//checks for 7
          {
            digitalWrite(7, LOW);    // set pin 7 low
            Serial.println(F("Led 7 Off"));
            Serial.println();
          }     
          if(readString.indexOf('8') >0)//checks for 8
          {
            digitalWrite(8, HIGH);    // set pin 8 high
            Serial.println(F("Led 8 On"));
            Serial.println();
          }
          if(readString.indexOf('9') >0)//checks for 9
          {
            digitalWrite(8, LOW);    // set pin 8 low
            Serial.println(F("Led 8 Off"));
            Serial.println();
          }         

          //clearing string for next read
          readString="";

        }
      }
    }
  }
} 

//////////////////////////
void sendGET() //client function to send and receive GET data from external server.
{
  if (client.connect(serverName, 80)) {
    Serial.println(F("connected"));
    client.println(F("GET /~shb/arduino.txt HTTP/1.1"));
    client.println(F("Host: web.comporium.net"));
    client.println(F("Connection: close"));
    client.println();
  } 
  else {
    Serial.println(F("connection failed"));
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read();
    Serial.print(c);
  }

  Serial.println();
  Serial.println(F("disconnecting."));
  Serial.println(F("=================="));
  Serial.println();
  client.stop();

}