The Sendmail Function on JavaScript

The Sendmail Function on JavaScript thumbnail
Use JavaScript to link your Web forms to sendmail.

Sending mail from a Web server is usually accomplished using sendmail, an open-source background service used by most Web hosts. In JavaScript there's no integrated method of sending mail, but using JavaScript functions you can access sendmail to send the contents of an HTML email link or Web form directly to your email box.

  1. JavaScript and Email

    • For security reasons, JavaScript doesn't have a built-in function to send email. However, JavaScript offers other functions that you can use to send email from your Web pages, either by using the HTML mailto function or the sendmail program. Combined with JavaScript form validation functions, you might consider using JavaScript to assist with your site's email and form submission.

    Advantages

    • When you create an email link or a Web form, you might use a link beginning with "mailto" to send the message using the visitor's browser and email program:

      <a href="mailto:youremail@example.com">Email Me!</a>

      Unfortunately, this method depends on the visitor's browser and email application. If either one doesn't work properly the email link will generate an error or simply do nothing. Using JavaScript you can send the email using a path to an application on the server, bypassing the visitor's software. JavaScript is also helpful for validating form submissions and hiding your email address from Web spiders that harvest addresses for spammers.

    Disadvantages

    • Most JavaScript email code examples send e-mail using the visitor's browser and email application, which is handled just as well and with less code using the HTML mailto function. Advanced JavaScript skills are necessary for customizing and troubleshooting code that connects to server-side scripts. Most email functions are more easily accomplished using freely available Perl CGI scripts.

    Best Practices

    • Consider using the simplest method for email that includes the security you want. Most Web hosts offer an email script that uses sendmail or a similar server-side method to enable form submissions without the disadvantages of the mailto method. Instead of HTML email links, have your visitors use a contact form. The best use for JavaScript is form validation, ensuring visitors' return email addresses are correctly formatted and that mandatory fields are completed correctly.

Related Searches:

References

Resources

  • Photo Credit Michael Blann/Lifesize/Getty Images

Comments

Related Ads

Featured