Sending eMail via PHP page

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!

Can you hard code all the mail parameters on the PHP side and get it to send mail?

What do you mean ? Use the SSL/TLS standard to encode the message ?

I mean divide and conquer - can the PHP page send an email without having to have the Arduino involved. Hit it from a browser perhaps.

I tried to change the mail service provider from Sendingblue ( intergrated in my web site AlterVista ) with IFTTT, and now it running very well ! Probably Sendingblue is not good to provide the service that I was looking for. I have also changed the Arduino source code because IFTTT wants a safe connection ( TLS/SSL ). Naturally IFTTT is not integrated with my web site but there are many possibilities to connect a big number of services.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.