Jump to content

Recommended Posts

How do I send the data entered in this form, to my email inbox?

 

<html>
<body>

<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/83504-send-form-email/
Share on other sites

Something like this should work.

 

<?
if(isset($_POST['firstname'])){

// Grab Post Vars
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$age = $_POST['age'];

// Set email vars
$from = "";
$cc = "";
$bcc = "";
$headers = "From: $from \r\n";
$headers .= "Cc: $cc \r\n";
$headers .="Bcc: $bcc \r\n";
$message = "First Name = $firstname \n Last Name = $lastname \n Age = $age";
$subject = "Email Form";
$headers .="Content-Type: text/plain; charset=UTF-8; format=flowed\n".
"MIME-Version: 1.0\n".
"Content-Transfer-Encoding: 8bit\n".
"X-Mailer: PHP\n";

// Send Email
@mail($to, $subject, $message, $headers);
}
?>
<html>
<body>

<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

</body>
</html>

 

This is obviously very basic.  You should validate and clean the input before sending the email.

Link to comment
https://forums.phpfreaks.com/topic/83504-send-form-email/#findComment-424851
Share on other sites

The quickest way would be something like this:

<?php
if (isset($_POST['submit'])) {
   $to = 'your.email@here.com';
   $subject = 'Form filled out';
   $body = print_r($_POST,true);
   $from = 'From: formpost@yourdomain.com';
   $param5 = '-f formpost@yourdomain.com';
   mail($to,$subject,$body,$from,$param5);
}
?>
<html>
<body>

<form method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" name="submit" />
</form>

</body>
</html>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/83504-send-form-email/#findComment-424891
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.