Wordpress: add input box values in mailto body text - html

I am trying to create a simple form which collects four items of info to send via the users own email to a supplier to request permission for 3rd party access to some of their data.
screen shot
Your Name:
Farm Supply Number 1:
Farm Supply Number 2:
Farm Supply Number 3:
Email your supplier here
Could you please advise how I can insert the text
Many thanks

Taking if from here: I am looking to collect data from input boxes and then use this text in the body of the email. Thank you. I wrote the following for you:
<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$supplier1 = $_POST['supplier1'];
$supplier2 = $_POST['supplier2'];
$supplier3 = $_POST['supplier3'];
$to = "your_email#gmail.com"; // example, fill in your own
$subject = "Mail sent from the form on the website by ".$name;
$message = $name." has sent in the following suppliers:\r\nSupplier 1: ".$supplier1."\r\nSupplier 2: ".$supplier2."\r\nSupplier 3:".$supplier3;
mail($to, $subject, $message);
echo "E-mail has been sent."
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="name">Your name : </label><input type="text" name="name" required><br>
<label for="supplier1">Farm supply number 1 : </label><input type="number" name="supplier1" required><br>
<label for="supplier2">Farm supply number 2 : </label><input type="number" name="supplier2" required><br>
<label for="supplier3">Farm supply number 3 : </label><input type="number" name="supplier3" required><br>
<input type="submit" name="submit" value="Click here to send e-mail"
</form>
If anything doesn't work, let me know, I didn't test this.
If you want to add security then use things like the htmlentities() function.
You will get things like
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
and
$supplier1 = htmlentities($_POST['supplier1']);
You could also add some extra security on checking if the fields are actually filled in before sending, I used required on the html, but this is no guarantee. I would also suggest you let people fill in any information so that you can contact them, like e-mail or phone.
Have more information here:
Using PHP_SELF
PHP Mail function
HTML Form

Related

How do I send an E-mail from a webpage?

I've been trying to learn the basics of HTML, and in doing this I've been designing my own rudimentary webpage. I don't plan on making it public at all, but it's good to help me to learn all of the different aspects of both HTML and CSS. In doing this, I've added a Contact section on one of the pages, that includes both an email address and a form that allows for an E-mail to be sent, I used one of the tutorials on W3Schools to create it. For the purposes of this I have removed my own email address, and replaced it with someone#example.com, but here is the output of this specific part of the code:
However, whenever I try to fill the form in to test it, I get this pop-up message. If I click cancel, then nothing happens, but if I click OK then then the mail app on my computer is opened. But the message that I typed into the form isn't there, and the E-mail address that I type into the box to send from is just changed to the default address on my computer.
So what can I do to prevent this pop-up message, and to just send the e-mail to me?
Here is the relevant code from the HTML document:
<h2 style = 'font-weight:normal'><a name = 'Contact' id = 'Contact'></a>Contact me:</h2>
<p>
You can reach me at: someone#example.com <br />
Or by just using the form below
</p>
<form action = 'mailto: someone#example.com' method = 'post' enctype = 'text/plain'>
<input type = 'text' name = 'name' placeholder = 'Name'> <br />
<br />
<input type = 'text' name = 'mail' placeholder = 'E-mail'> <br />
<br />
<input type = 'text' name = 'comment' size = '50' placeholder = 'Comment'> <br />
<br />
<input type = 'submit' value = 'Send'>
<input type = 'reset' value = 'Reset'>
</form>
If HTML isn't going to be enough to send an e-mail from a webpage, and I need another language to write a program that can do it, I am quite competent in Python, and I know C# to some extent. However, I've never used JavaScript, PHP, Perl, or anything else (I don't know what sort of languages would be appropriate)
If you want to submit the form to go to an email it's simple really. You could use a simple server-side language like PHP. You'll need 3 files. One file that houses the front-end form contents, one file that processes the form once the user hits the submit button and a thank you page after the form gets sent to let the user know that the form has been submitted. Here is a demo below.
HTML:
<form action="processor.php" method="post" id="myForm">
<label for="firstname"></label>
<input type="text" name="firstname" placeholder="First Name" id="firstname" required>
<label for="lastname"></label>
<input type="text" name="lastname" placeholder="Last Name" id="lastname" required>
<label for="email"></label>
<input type="email" name="email" placeholder="Email" id="email" required>
<label for="comments"></label>
<textarea rows="4" cols="32" name="comments" id="comments" placeholder="Questions & Comments"></textarea>
<input type="submit" value="Submit">
</form>
PHP (processor.php file)
/***********************************************************/
/******* Set the receipient email address below ********/
/******* And set the subject line of the email ********/
/*$recipient_email = "testemail#yahoo.com";*/
$recipient_email = "testemail#yahoo.com";
$email_subject_line = "Mail from Website";
/***********************************************************/
/***********************************************************/
if(isset($_POST['firstname']))
{
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
$email = $_POST['email'];
$comments = $_POST['comments'];
if(!empty($firstName) &&
!empty($lastName) &&
!empty($email) &&
!empty($comments))
{
$message = "Name: $firstName, Lastname: $lastName, Phone: $phoneNumber,
Email: $email, Comments: $comments";
send_mail($email, $message, $recipient_email, $email_subject_line);
}
}
function send_mail($email, $message, $recipient_email, $email_subject_line)
{
$to = $recipient_email;
$from = $email;
$subject = $email_subject_line;
$headers = "From: {$email}" . "\r\n" . 'Reply-To:' . $email . "\r\n" . 'X-
Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
header("Location:thankyoupage.php");
thankyoupage.php (After data has been submitted)
<div class="thankyoucontainer">
<h1>Thank you, your message has been submitted.</h1>
Go back to home page
</div>

Send all data from inputs in a form through email without defining each field

I have like 150+ forms with different input IDs. I need to collect all the data from the inputs and send them over through email directly without defining those fields. I see that the site https://formspree.io/ has that feature but I want to know how I can implement that myself. Thank you!
This how the site handles the form:
<form action="//formspree.io/your#email.com"
method="POST">
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
</form>
This allows all inputs to be sent directly to the given email.
Nevermind, got the answer.
foreach ($_POST as $key => $value)
$body .= $key . ' -> ' . $value . '<br>';

How to submit a contact form via custom button using "href" code?

For my website I'm working on a contact form, which works. But I want the submit button to be like other buttons on my site, meaning I want it to be styled like the code below.
However, I can't get it to submit via a "href" code.
I've tried applying answers on similar questions but haven't had any luck.
Any help would be greatly appreciated!
THE STYLE FOR THE SUBMIT BUTTON I WANT TO USE:
<div class="section-buttons">
<p class="button layer" data-depth="0.10" ><a href = "I WANT THIS TO SUBMIT THE FORM"
class="y1 knop roll swing"><span class="g1">SUBMIT</span><span class="g2">SUBMIT</span>
</a></p>
</div>
THE FORM CODE:
<form action="form.php" method="post" enctype="multipart/form-data">
<label></label>
<input name="name" required placeholder="Name">
<label></label>
<input name="email" type="email" required placeholder="E-mail">
<label></label>
<textarea name="message" cols="20" rows="5" required placeholder="Message">
</textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
EDIT:
Thanks a lot for the quick replies. Really appreciated.
Celt, your solution definitely brings me close to the solution.
It does indeed bring me to the form.php but it doesn't seem to submit the actual data to an email address.
Could it be that my PHP file (forms.php) does something wrong with the new code? I'm guessing the last part "if ($_POST['submit'])" doesn't quite work with this new approach? Any help?
Sorry for the noobness.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website.com';
$to = 'email#email.com';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email!</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message
again.</p>';
}
}
?>
This should work for you:

How to create simple contact form?

I found this example on w3schools and change email to my email, but when I click Send nothing happens. Where is the problem?
<h3>Send e-mail to someone#example.com:</h3>
<form action="MAILTO:someone#example.com" method="post" enctype="text/plain">
Name:<br>
<input type="text" name="name" value="your name"><br>
E-mail:<br>
<input type="text" name="mail" value="your email"><br>
Comment:<br>
<input type="text" name="comment" value="your comment" size="50"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
Don't do this. It is unreliable as it depends on the mail client the user has installed and you can not test for that.
instead you should either post the form data to a php script that uses the
php mail() function - which is easy to learn
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = $_POST['comment'];
$headers = 'From:'. $_POST['email']. "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
or use a cgi script like
http://www.response-o-matic.com/
You aren't really sending the email when you use the mailto:someone#example.org All you're doing is telling the browser that it should handle what follows as an email address and so, the browser will open the default mail client.
The only way to send an email programmatically, which I think is what you are trying to do, is to use a server side script. Something like PHP or ASP.NET to just give two examples.

html help on my contact form please?

I need some help, I'm building a website for a good friend and I need some help with the contact form. I found the code online but it's not working correctly. It sends the e-mail but not all the forms correctly, and doesn't send the picture. Also, when I send the form, it should link to the page contactus.html, but the link doesn't seem to work either. Can anyone help correct this code, this would help SO much. Thank you so, so much.
Here is the HTML for the contact form:
<div id="stylized" class="myform">
<form id="form" id="form" action="mail.php" method="POST">
<label>Name
<span class="small">Add your name</span>
</label>
<input type="text" name="name">
<label>Address
<span class="small">Add your home address</span>
</label>
<input type="text" name="address">
<label>Phone
<span class="small">Add a Phone Number</span>
</label>
<input type="text" name="phone">
<label>E-mail
<span class="small">Enter a valid E-mail</span>
</label>
<input type="text" name="email">
<label>Timeline
<span class="small">Range for your project</span>
</label>
<input type="text" name="timeline">
<label>Photo
<span class="small">Upload current picture</span>
</label>
<input type="file" name="photo">
<label>Description
<span class="small">Type Your Project Description</span>
</label>
<textarea name="message" rows="6" cols="25"></textarea>
<button type="submit" value="Send" style="margin-top:15px;">Submit</button>
<div class="spacer"></div>
</form>
</div>
And here is mail.php, which is supposed to help make the form work. I think here is where the problem is:
<?php $name = $_POST['name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$timeline = $_POST['timeline'];
$description = $_POST['description'];
$formcontent="From: $name \n Message: $message";
$recipient = "blanger#hawaii.edu";
$subject = "New Project Request from 2DadsDB.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contactus.html'>Go Back</a>";
?>
As Blender pointed out the code is very insecure. It's easy for malicious content to be inserted. Also there's no reference in the mail.php to "photo"
$fileImage = $_POST['photo'];
You'll need to use a script to upload and store the photo I believe. It's best too look at a tutorial or complete source instead of building from scratch.
The mail() function is good for only message sending.
To send an image First you need to upload your photo to the server To upload an image.
To send an image using mail() first attach your photo from server to mail() PHP e-mail attachment script
And use $name = mysql_real_escape_string(strip_tags($_POST['name']));
for each post like name,e-mail etc., for security purpose.
You should sanitize your imputs.Use mysql_real_escape_string or stripslashes function on each of the $_POST.
$user = mysql_real_escape_string($_POST['user']);