php newsletter (email with empty fields)

Asked

Viewed 143 times

3

Can someone please help me?

I saw this on the net and tried to take advantage, however in my email I receive the fields "Name:" and "Email:" but they are completely empty, but when sending I send with the fields filled!

index.html

<form method="POST" action="newsletter.php">
                        <li>
                            <input type="text" class="text" value="Nome">
                        </li>
                        <li>
                            <input type="text" class="text" value="Email">
                        </li>
                            <input type="submit" value="submit">
                    </form>

php newsletter.

# RESULT PAGE
$location = "";

## FORM VALUES ##

# SENDER - WE ALSO USE THE RECIPIENT AS SENDER
# DON'T INCLUDE UNFILTERED USER INPUT IN THE MAIL HEADER!
# SEE ALSO: How to protect a php Email Form using php mail or mb_send_mail against Mail Header Injection
$sender = $recipient;

# MAIL BODY
$body = "Name: ".$_REQUEST['Nome']." \n";
$body = "Email: ".$_REQUEST['Email']." \n";
# add more fields here if required

## SEND MESSGAE ##

mail($subject, $body, "From: $sender" ) or die ("O email não pode ser enviado.");

## SHOW RESULT PAGE ##

header( "Location: $location" );
?>

Thank you

  • I already changed, javascript was part of another approach, nothing to be :)

  • If the method is always POST I think it’s best to exchange $_REQUEST for $_POST.

1 answer

6


Missing attribute name in its inputs.

<input type="text" class="text" value="Nome" name="Nome">
<input type="text" class="text" value="Email" name="Email">

Not to mention php you replace the content of $body the second time you assign value to it. Right would be something like this:

$body = "Name: ".$_REQUEST['Nome']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
  • Solved! Thank you!

  • You’re welcome, whenever I can help^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.