开发者

How do I get the email address to show up in the body of the message?

开发者 https://www.devze.com 2023-01-06 19:45 出处:网络
I have a very simple form where users can enter their email and click submit to request a newsletter.

I have a very simple form where users can enter their email and click submit to request a newsletter.

PHP generates an email but it does not include the one important element: the subscriber's email!

Here is the HTML:

<form action="news.php" method="post">
            <fieldset>
            <input type="text" id="your-email" value="YOUR EMAIL ADDRESS" onfocus="if (this.value=='YOUR EMAIL ADDRESS') this.value='';" />
            <input type="submit" value="::Submit Query::" id="red-submit" />
            </fieldset>
</form>

Here is the PHP:

<?php
$emailFrom = $_POST['email'];

    $emailTo = "forrest@rouviere.com";
    $subject = "Moving Simplified News Request";

   if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
    } else {
        $emailHeaders = 'From: "The Boss" <noreply@movingsimplified.com>';
    }

    // Create a string representing the body. "\n" creates a new line. The ".=" operator appends the string onto the existing string.
    $body = "Email: ".$emailFrom."\n";

    /* Send Email */
    if (mail($emailTo, $subject, $body,   $emailHeaders)) {
        echo 'Thank you! Your message has been sent.';

    } else {
        echo 'There was an internal error while sending your email.<br>';
        echo 'Please try again later.';    
    }
 ?>

However, when I get the email notice the bod开发者_JAVA百科y of the message only contains the following:

Email:

I would appreciate some help getting the subscribers email to show up like this:

Email: mark@twain.com

Thanks!


set the name attribute of the input field to email in your html. It's currently not set.

0

精彩评论

暂无评论...
验证码 换一张
取 消