-1
I have an HTML form, and I’m using a PHP code to send the data via email. However, I would like to send by e-mail only the data of the fields filled, and their respective names.
Example:
[ ] Nuggets
[3] Hot Dog
[1] Cheese Burger
[ ] Pizza
[ ] Salad
The email flips with all text field, including items that have no marked drive, and would like it to come as follows:
[3] Hot Dog
[1] Cheese Burger
I am using the code below to send the email with the fields (which in case the fields do not match the ones above, was just an example):
<?php
if(isset($_POST['submit'])){
$to = "[email protected]"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
Everything is working, I have customized the code above to put the fields I really need in the form. I believe it is necessary to use IF, in this PHP file, but I am not sure and do not know how to do it.
I apologize if the post code was put wrong, but it’s my first time on the forum. (yes I read the instructions)
From now on, thank you.
PS: HTML code
<html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="mail_haddor.php" method="post">
First Name: <input type="text" name="first_name" size="40"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
As I commented initially, the example cited does not match the basic code I used. In this case, it would be like, send and appear in the body of the email, only the fields filled as first name, second name, email. If you just fill out your first name, I don’t want you to come in for example:
Name: Mário
Middle Name:
E-mail:
I want you to show up:
Name: Mário
The example was with food, because it will be used with food.
If possible click on [Edit] and post your HTML code.
– Valdeir Psr
The post has already been edited and added the HTML code.
– scti