RISOLTO Ricever indirizzo IP del mittente su un contact form

Pubblicità
Stato
Discussione chiusa ad ulteriori risposte.

S.t.e.r.l.o.k.

Utente Èlite
Messaggi
1,895
Reazioni
119
Punteggio
101
Salve a tutti

In questo contesto PHP, all'interno di un conctat form, che viene richiamato dalla pagina html... mi spareste dire la stringa da aggiungere per ricevere la e-mail dal conctat form con l'IP del mittente:

PHP:
 <?php
 
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];

    $from_add = "info@sitointernet.com";
 
    $to_add = "miaemail@gmail.com";
    
    $subject = "RICHIESTA SITO INTERNET";
    
    $message = "Name*:$name \n Email*: $email \n Phone: $phone \n
Message*: $message";
    
    $headers = "From: $from_add \r\n";
    $headers .= "reply-to: $email \r\n"; 
    $headers .= "Return-Path: $from_add\r\n";
    $headers .= "X-Mailer: PHP \r\n";
 
    
    if(mail($to_add,$subject,$message,$headers))
    {
        $msg = "Mail sent";
    }

    
print "<p> grazie $name per il tuo messaggio,
    ti contatteremo a breve. <a href=\"http://www.sitointernet.com\">Clicca qui</a>
    per tornare al sito </p>" ;
 
non sono espertissimo in php, lo mastico, prova così:
Codice:
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

// Ottieni l'indirizzo IP del mittente
$ip_address = $_SERVER['REMOTE_ADDR'];

$from_add = "info@sitointernet.com";
$to_add = "miaemail@gmail.com";
$subject = "RICHIESTA SITO INTERNET";

// Aggiungi l'IP del mittente e l'email al messaggio
$message = "Name*: $name \nEmail*: $email \nPhone: $phone \nMessage*: $message \nIP Address: $ip_address";

$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $email \r\n";
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";

if (mail($to_add, $subject, $message, $headers)) {
    $msg = "Mail sent";
}

print "<p>grazie $name per il tuo messaggio, ti contatteremo a breve. <a href=\"http://www.sitointernet.com\">Clicca qui</a> per tornare al sito</p>";
?>
--- i due messaggi sono stati uniti ---
anzi scusa, secondo me meglio modificare qualcosa:

PHP:
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];

$message_content = $_POST['message'];

// Ottieni l'indirizzo IP del mittente
$ip_address = $_SERVER['REMOTE_ADDR'];

$from_add = "info@sitointernet.com";
$to_add = "miaemail@gmail.com";
$subject = "RICHIESTA SITO INTERNET";

// Costruisci il messaggio
$message = "Name*: $name \nEmail*: $email \nPhone: $phone \nMessage*: $message_content \n\nIP Address: $ip_address";

$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $email \r\n"; //
$headers .= "Return-Path: $from_add\r\n";
$headers .= "X-Mailer: PHP \r\n";

// Invia l'email
if (mail($to_add, $subject, $message, $headers)) {
    $msg = "Mail sent";
}

// Messaggio di ringraziamento
echo "<p>Grazie $name per il tuo messaggio, ti contatteremo a breve. <a href=\"http://www.sitointernet.com\">Clicca qui</a> per tornare al sito.</p>";
?>

Ho rinominato la variabile da $message a $message_content per evitare sovrapposizioni con la variabile $message che contiene il testo del messaggio email.
 
Ultima modifica:
ok grazie ho caricato sul server ftp e ho testato il tutto, con qualche correzione e fix, Chat-Gpt mi ha risolto la situazione, e grazie, anche al tuo aiuto, ciao
 
Stato
Discussione chiusa ad ulteriori risposte.
Pubblicità
Pubblicità
Indietro
Top