How to create simple contact form? - html

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.

Related

"POST /mail.php" Error (404): "Not found"

I'm trying to make a simple contact form but I keep getting this error while trying to submit a response. The code is:
HTML :
<form action="mail.php" method="POST" class="submitphoto_form">
<input type="text" name ="name" class="wp-form-control wpcf7-text" placeholder="Your name">
<input type="mail" name="email" class="wp-form-control wpcf7-email" placeholder="Email address">
<textarea name="message" class="wp-form-control wpcf7-textarea" cols="30" rows="10" placeholder="What would you like to tell us"></textarea>
<input type="submit" value="Submit" class="wpcf7-submit">
</form>
PHP :
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "shaliniguha2#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-
decoration:none;color:#ff0099;'> Return Home</a>";
?>
Both the files are in the same folder.
There are three possibilities you get this error message
A) File name is not valid that you have (check case insensitivity)
B) Extension is invalid or not mentioned
C) File path is incorrect (check cases and double check file presence)
You need to configure your apache server locally if you are not working on a server because php scripts runs only on a server environment where php is installed.
In case you have apache server installed already, check if its running and your working directory is correct.

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>

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:

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']);