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

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>

Related

HTML mailto form

Can anyone help me with my feedback form for a website I am building?
I am not receiving any errors when I run this, although it doesn't actually send any email at all.
The following is the code I am trying to use:
<form action="mailto:admin#example.com" enctype="text/plain" method="post">
<p>Name: <input name="Name" type="text" id="Name" size="40"></p>
<p>E-mail address: <input name="E-mail" type="text" id="E-mail" size="40"></p>
<p>Comment:</p>
<p><textarea name="Comment" cols="55" rows="5"
id="Comment"></textarea></p>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
Sending mail from HTML Form is not a right option to do, you are using an HTTP Method (POST), so you have to set a http/https link from your action value. Otherwise, you have to send the email using the href tag, including a subject and body parameters.
E.g: Send Message
The mail application installed in your machine would automatically opened when you click that link.(Outlook, Gmail,...) and you can choose which one you have to send the mail within it.
you should maken a .php file
eg.
<form method="post" action="mail.php">
then in your mail.php put something like this:
<?php
session_start();
$to = "contact#webmagico.be"; // this is your Email address
$from = htmlspecialchars($_POST['email']); // this is the sender's Email address
$naam = htmlspecialchars($_POST['naam']);
$email = htmlspecialchars($_POST['email']);
$messageText = $naam . " " . $email . " wrote:" . "\n\n" . htmlspecialchars($_POST['bericht']);
$message = array(
"ontvanger" => $to,
"zender" => $from,
"naam" => $naam,
"email" => $email
);
$valid = true;
foreach($item in $message)
{
if(!isset($item) || $item === "")
{
$valid = false;
}
}
if($valid)
{
mail($to, $naam, $message, "From:" . $email);
}
else
{
$_SESSION['error'] = "Forgot something!"
}
/*file that gives the response*/
header('Location: thankyou.php');
?>
You can find different alternatives about a post-form on the web.
Hope this helps.

Wordpress: add input box values in mailto body text

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

E-mail box for HTML website

So I have made myself a website. Since it has plans for being used I need someones help :)
I need users to fill in a few boxes and then send it to my email at thisismyemail#provider.com.
Since I am a little new I dont now how to do it.
The form: http://imgur.com/U5Q3jrE
This is my code:
<form action="../index.html" method="post" class="message">
<input type="text" value="Naam" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<input type="text" value="E-mail" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<input type="text" value="Onderwerp" onFocus="this.select();" onMouseOut="javascript:return false;"/>
<textarea></textarea>
<input type="submit" value="Send"/>
</form>
Now what I need is that it doesnt bring me to the index page but show a message with someone like: "Your message has been send" and that it sends it to my email, because at the moment it doesnt send it to anything.
Once more I am pretty new so please forgive my noobness :P
Thanks everyone,
Waylon194
Ok here's a php html code that can be used to email, that you can start with.
User inputs must always be sanitized accordingly. This code is just for demonstration.
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "someone#example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post">
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
<?php
}
?>

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:

Wordpress Custom Registration Form

I have a client that needs a custom registration form.
I need to make a custom design on this page
I need to add custom fields like First Name, Company, Phone, etc.
Someone can help me with this?
A better place to ask WordPress questions is probably on WordPress Answers. Anyhoo, if you want to solve this without plugins, you need three things:
A custom WordPress theme
A Page Template
A WordPress Page that uses the Page Template
When you have these three parts in place, you can do the following in your Page Template:
<?php
/*
Template Name: Registration
*/
global $current_user;
wp_get_current_user();
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$company = $_POST['company'];
if (($firstname != '') && ($lastname != '') && ($company != '')) {
// TODO: Do more rigorous validation on the submitted data
// TODO: Generate a better login (or ask the user for it)
$login = $firstname . $lastname;
// TODO: Generate a better password (or ask the user for it)
$password = '123';
// TODO: Ask the user for an e-mail address
$email = 'test#example.com';
// Create the WordPress User object with the basic required information
$user_id = wp_create_user($login, $password, $email);
if (!$user_id || is_wp_error($user_id)) {
// TODO: Display an error message and don't proceed.
}
$userinfo = array(
'ID' => $user_id,
'first_name' => $firstname,
'last_name' => $lastname,
);
// Update the WordPress User object with first and last name.
wp_update_user($userinfo);
// Add the company as user metadata
update_usermeta($user_id, 'company', $company);
}
if (is_user_logged_in()) : ?>
<p>You're already logged in and have no need to create a user profile.</p>
<?php else : while (have_posts()) : the_post(); ?>
<div id="page-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="content">
<?php the_content() ?>
</div>
<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
<div class="firstname">
<label for="firstname">First name:</label>
<input name="firstname"
id="firstname"
value="<?php echo esc_attr($firstname) ?>">
</div>
<div class="lastname">
<label for="lastname">Last name:</label>
<input name="lastname"
id="lastname"
value="<?php echo esc_attr($lastname) ?>">
</div>
<div class="company">
<label for="company">Company:</label>
<input name="company"
id="company"
value="<?php echo esc_attr($company) ?>">
</div>
</form>
</div>
<?php endwhile; endif; ?>
Now, when you want to retrieve the stuff you've stored, you need to know whether the information is within the User object itself or in metadata. To retrieve the first and last name (of a logged-in user):
global $current_user;
$firstname = $current_user->first_name;
$lastname = $current_user->last_name;
To retrieve the company name (of a logged-in user):
global $current_user;
$company = get_usermeta($current_user->id, 'company');
That's the basic gist of it. There's still a lot of stuff missing here, like validation, error message output, the handling of errors occurring within the WordPress API, etc. There's also some important TODO's that you have to take care of before the code will even work. The code should probably also be split into several files, but I hope this is enough to get you started.
An advantage of using a custom registration form is that modifying the code according to the user's needs becomes easy. For a custom submit form you can make use of existing hooks in Wordpress like template_redirect and then map that hook to some function which will do the post-processing of the form, like validation and submitting data to the site's database. You can refer to an in-depth article here.
<div class="employee">
<input type="hidden" name="show_msg">
<form name="customer_details" method="POST" required="required" class="input-hidden">
Your Name: <input type="text" id="name" name="customer_name">
Your Email: <input type="text" id="email" name="customer_email">
Company: <input type="text" id="company" name="company">
Sex: <input type="radio" name="customer_sex" value="male">Male <input type="radio" name="customer_sex" value="female">Female
<textarea id="post" name="experience" placeholder="Write something.." style="height:400px;width:100%"></textarea>
<input type="submit" value="Submit">
<!--?php wp_nonce_field( 'wpshout-frontend-post','form-submit' ); ?-->
</form></div>
PHP function
function wpshout_frontend_post() {
wpshout_save_post_if_submitted();
}
add_action('template_redirect','wpshout_frontend_post', 2);
A custom WordPress registration form has two major advantages over the standard form.
The first is the integration with the overall look and feel of the website theme. Standard forms often don’t work well with custom themes and there is always a chance that the custom CSS files do not render well with the form. A custom form, on the other hand, can be easily set up to work with custom CSS.
The second and more popular reason of using a custom registration form is the option of custom fields that are not included on the standard form. A small custom registration form speeds up the process and collects all the necessary data from a neat interface.
function wordpress_custom_registration_form( $first_name, $last_name, $username, $password, $email) {
global $username, $password, $email, $first_name, $last_name;
echo '
<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
First Name :
<input type="text" name="fname" value="' . ( isset( $_POST['fname']) ? $first_name : null ) . '">
Last Name:
<input type="text" name="lname" value="' . ( isset( $_POST['lname']) ? $last_name : null ) . '">
Username <strong>*</strong>
<input type="text" name="username" value="' . ( isset( $_POST['username'] ) ? $username : null ) . '">
Password <strong>*</strong>
<input type="password" name="password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '">
Email: <strong>*</strong>
<input type="text" name="email" value="' . ( isset( $_POST['email']) ? $email : null ) . '">
<input type="submit" name="submit" value="Register"/>
</form>
';
}
This form can be inserted anywhere by using the shortcode [wp_registration_form]. Here is the code snippet for setting up the shortcode:
function wp_custom_shortcode_registration() {
ob_start();
wordpress_custom_registration_form_function();
return ob_get_clean();
}
I hope that by now you have a fair idea of creating a WordPress custom Registration form.Still any confusion kindly check Build Custom WordPress Registration Forms