How do I send an email from a web page / web form?

What methods are available for sending email via a web page or a form on a web page?

I have a premise that you are submitting form data to a script, but I really don't know what a cgi script is (I would like to know if this is the suggested method!) Or what the current practice is.

This is simply to provide users with a way to contact operators. The form on the page seems to be easier for the user than asking them to open the mail client. I was also worried about bots collecting the contact email address (in the case of mailto: links).

0


source to share


6 answers


When a form is submitted, the data in that form is sent to the server side script. For example, in PHP you access data with an array $_POST

, <input name="">

it becomes an array index .. For example ..

// <form action="mailer.php">[..]<input name="subject" [..]><input name="content" [..]></form>
echo("The subject is: ". $_POST['subject']);
echo("The content is:" . $_POST['content']);

      

At the most basic level, all you have to do is use the programming languages โ€‹โ€‹created in the mail function. Again, in PHP it's simple mail()

:

mail($to, $subject, $message);

      



You just set $to

to your email address (do not allow the user to set this, or they can send mail as "you", "spam" to anyone ..) $subject

and a $message

form will be given$_POST[]

Before you submit any HTML file that is sent to the script from mail("me@example.com", $_POST['subject'], $_POST['content']);

, consider what happens if someone reloads this page 200 times. You must have some sort of security, maybe and / or speed limit.

One thing that's bugged me before - remember that a "contact form" is not a substitute for providing an actual email address! For example, my email client keeps a copy of all mail I send, and I can attach files, and it's much nicer to write in a familiar email client than in a form <textarea>

(especially when I accidentally get "back" and the form decides to clear itself)!

+3


source


For most unix / bsd / linux systems, most languages โ€‹โ€‹provide a shell around the Mail command.



+1


source


If you are using ASP.NET 2.0 you can use the System.Net.Mail namespace. More information here

0


source


Today's web development languages โ€‹โ€‹usually have libraries for sending email. it depends on which language you are using, but you will find it in your language documents. it's pretty simple, a library within your language usually encapsulates and exposes the "smtp client" behavior that you use. you provide the mail message to the sender and recipient and the data to connect to your SMTP server.

or you can sometimes use the SMTP capabilities on the computer where your web server is located, if available. I'm not sure if it will be worse for the email on the recipient's server because your server cannot be recognized by the mail server for the domain ... someone with more experience can comment on this.

0


source


Well, here's what not to do:

<a href="mailto:someperson@someaddress.com">Please spam me, kthx</a>

      

This is the best code pattern for allowing users to enter a form, misinform the input and format it however you see fit, and then feed the data to the post function in the language of your choice.

0


source


Sending mail should be done on the server side - changing the specifics depends on your server language, your operating system, and what access to your server belongs to the SMTP server.

If you're looking for an easy way to add a contact form to a blog or public website, try Wufoo - you can add a contact form that will send you email very easily (up to three forms for free). I am not affiliated with them, I just think they are cool.

0


source







All Articles