Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

Create a HTML form that submits from the fillers mail address to my email address

$
0
0

I have a HTML form on my site that submits using a very simple PHP script. As the script is written now I receive the form in my email address, the email that i receive has both the To and From fields as my email address. I.E if person1@email.com fills in the form I receive an email that says

From : my_email@email.com
To   : my_email@email.com

I would like to change the script so that the From is the persons email address that filled in the form. I.E the mail I receive should be:

From : person1@email.com
To   : my_email@email.com

This way I will be able to set up a automated reply on the mail account so that as a person fills in the form they will receive a welcome mail from my account.

Below is the HTML form code that I use:

<form action="../php/submit-candidate-form.php" enctype="multipart/form-data" method="post">
       <p>1) What is your name?</p>
            <input class="input" type="text" name="name" placeholder="Name" required>

       <p>2) What is your E-Mail address?</p>
            <input class="input" type="email" name="email" placeholder="Email" required>


    <button class="main-button icon-button">Submit form</button>

And this is the simple php script that I use:

<?php
$subject = 'Email Subject line.';

$emailadd = 'my_email@email.com';

$url = 'http://www.example.com/thankyou';

$req = '0';

$text = "You have recieved the following message from the form:\n\n"; 
$space = '';
$line = '';
foreach ($_POST as $key => $value) {
    if ($req == '1') {
        if ($value == '') {
            echo "$key is empty";
            die;
        }
    }
    $j = strlen($key);
    if ($j >= 20) {
        echo "Name of form element $key cannot be longer than 20 characters";
        die;
    }
    $j = 20 - $j;
    for ($i = 1; $i <= $j; $i++) {
        $space .= '';
    }
    $value = str_replace('\n', "$line", $value);
    $conc = "{$key}:$space{$value}$line";
    $text .= $conc;
    $space = '';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

Viewing all articles
Browse latest Browse all 29748

Trending Articles