Goodmorning forum.
I have a problem with my project created to send a mail from a board Arduino Mega 2560 via PHP page loaded with the FTP service on my website Altervista ( the board is connected at Internet with the Ethernet Shield ). For my test, the Arduino sketch calls ( just once ) the PHP page, which will send of the message at recipient.
The Arduino code is the follow:
#include <SPI.h>
#include <Ethernet.h>
#define SEND_MAIL 7
char server[] = "xxxxxxxxxx.altervista.org";
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
void setup() {
Serial.begin(9600);
Serial.println("Init*");
Ethernet.begin(mac);
Serial.println("Ready!");
delay(1000);
pinMode(SEND_MAIL, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
if (digitalRead(SEND_MAIL)) {
// Send message
Serial.println("Connecting...");
if (client.connect(server, 80)) {
Serial.println("Connected!");
client.println("GET /my-files/mail.php?to=mario.rossi@tiscali.it&msg=Hello World by Arduino HTTP/1.1");
client.println("Host: xxxxxxxxxx.altervista.org");
client.println("Connection: close");
Serial.println("Done!");
} else {
Serial.println("Connection failed!");
}
}
// Check if there is an answer by server
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// End of the connection
if (client.connected()) {
Serial.println("Disconnected!");
client.stop();
digitalWrite(LED_BUILTIN, HIGH);
while(true);
}
}
The PHP code is the follow:
<?php
$to = $_GET["to"];
$subject = "Prova invio eMail";
$message = $_GET["msg"];
$headers = "From: Blog di XxxxxxXxx";
mail ($to, $subject, $message, $headers);
?>
I have loaded the PHP page on website Altervista and the Arduino sketch on board but don't run ... Do you have some idea on why ???
Thanks!