I wrote a small form to do what you wanted, with comments explaining the code.
This is a very simple form, and does not do any validation on input fields.
Note that depending on what you enter in as SENDEMAIL, it could end up as SPAM email in your SPAM or JUNK mail folder.
PHP Code:
<?php
define('RECIPIENTEMAIL','test@gmail.com'); // define your email (Recipient) here.
define('SENDEREMAIL','NoReply@gmail.com'); // define Senderemail here (Shows as Sender's email)
if (isset($_POST['submit']) ){ // check if submit button is clicked
$name = 'From: '.$_POST['name']."\r\n"; // name valaue in email body as first line.
$email = 'Email: '.$_POST['email']."\r\n"; // email value in email body as second line.
$body = $name.$email.$_POST['message']; // body first line, second line plus message
$subject = 'Web Message'; // shows as subject in email
$to = RECIPIENTEMAIL;
$header = 'From: '.SENDEREMAIL."\r\n";
if (@mail($to, $subject, $body, $header)){ // PHP mail function to send email.
echo '<b>Message send succeed</b><br />';
}else{
echo '<b>Message send failed</b><br />';
}
}
// a form to collect user name, email and message
echo '<table><form action="'.$_SERVER[PHP_SELF].'" method="post">
<tr><td><label>Name</label></td><td><input type="text" name="name"></td></tr>
<tr><td><label>Email</label></td><td><input type="text" name="email"></td></tr>
</table>';
echo '<table>
<tr><td><label>Message</label></tr>
<tr><td><textarea name="message" cols=50 rows=8></textarea></td></tr>
<tr><td align="right"><input type="submit" name="submit" value="Send Message"></td></tr></table>
</form>';
?>