-1

The form action is linked to this php script:

<?php

$email = $_POST['subscribefield'];

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo "Dit adres klopt niet";
  die();
}

$to = "flash1996mph@hotmail.com";
$subject = "Abonee voor de nieuwsbrief";
$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief";

mail($to, $subject, $body);

echo "U bent succesvol aangemeld voor de Vandenberg nieuwsbrief";
echo $_SERVER['REMOTE_ADDR'];
?>

At the end i added echo $_SERVER['REMOTE_ADDR']; then i checked my mail, but there was nothing. Did i use the code the wrong way?

EDIT:

<?php

$email = $_POST['subscribefield'];

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo "Dit adres klopt niet";
  die();
}


$to = "flash1996mph@hotmail.com";
$subject = "Abonee voor de nieuwsbrief";
$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief";
$body .= $_SERVER['REMOTE_ADDR'];

mail($to, $subject, $body);

echo "U bent succesvol aangemeld voor de Vandenberg nieuwsbrief";
?>

The above is an edit^

Kevin
  • 930
  • 3
  • 13
  • 34
  • 4
    `$body` is the content of the email. – chris85 Jun 09 '16 at 18:12
  • 2
    It might be marked as spam, because you're missing the headers. Read http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail -- also, are you running this on localhost or on a server somewhere? If the mail is sent, but you can't see the IP, it's because the IP isn't added into the `$body` variable, so it will not be sent with the mail. See the [`mail()`](http://php.net/manual/en/function.mail.php) documentation – Qirel Jun 09 '16 at 18:13
  • 1
    Oh i got the mail but it did not display the ip @Qirel – Kevin Jun 09 '16 at 18:14
  • thre was No ip @chris85 – Kevin Jun 09 '16 at 18:15
  • 3
    Like @chris85 pointed out first (beat me to the punch there ;-) ), the IP isn't part of the `$body` variable, so it will not be sent. Before the `mail()` call, add `$body .= $_SERVER['REMOTE_ADDR'];` and you'll see it. – Qirel Jun 09 '16 at 18:15
  • 2
    PHP can't time travel. You don't access the REMOTE_ADDR until **AFTER** you sent the email. – Marc B Jun 09 '16 at 18:16
  • worked fine for me. – Funk Forty Niner Jun 09 '16 at 18:29
  • did u get an IP @Fred-ii- – Kevin Jun 09 '16 at 18:33
  • weird i just get an email with 2 things – Kevin Jun 09 '16 at 18:33
  • 1
    @KevinAartsen I sure have. Make sure you uploaded the right file and that you're not victim of caching here. Your form does use the POST method, right? – Funk Forty Niner Jun 09 '16 at 18:34
  • Gosh i feel so stupid.. i was certain i had saved! but i didn't.. @Fred-ii- – Kevin Jun 09 '16 at 18:35
  • 2
    @KevinAartsen Ah... had a feeling about that ;-) not bad huh? *Cheers* – Funk Forty Niner Jun 09 '16 at 18:37

1 Answers1

1

When mail is called the email is sent. In your script $body is the body of the email so append the IP address on to that variable before you call the mail function.

$to = "flash1996mph@hotmail.com";
$subject = "Abonee voor de nieuwsbrief";
$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief";
$body .= $_SERVER['REMOTE_ADDR'];
mail($to, $subject, $body);

The echo currently just outputs the IP on the browser.

chris85
  • 23,846
  • 7
  • 34
  • 51
  • i added that now and still nothing just a mail only displaying this:$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief"; – Kevin Jun 09 '16 at 18:22
  • hehe i forgot to save :l – Kevin Jun 09 '16 at 18:36
  • 2
    [*Seems like I hit the nail right on the head...*](http://stackoverflow.com/questions/37733295/trouble-getting-users-ip?noredirect=1#comment62938619_37733295) hehe ;-) – Funk Forty Niner Jun 09 '16 at 18:36