How to Send Email from a Web Page

There are several different tools available that you can use to send emails from a web page. The following scripts are the most commonly used on our servers:

FormMail

Using a simple script (see below), you can quickly set up FormMail to send emails from a Contact Us page, for example.

<form method="post" action="https://www.example.com/cgi-bin/FormMail.pl" accept-charset="ISO-8859-1" onsubmit="var   originalCharset = document.charset; document.charset = 'ISO-8859-1';
  window.onbeforeunload = function (){document.charset=originalCharset;};">:

    Your Name    <input name="realname" />
    Your Email   <input name="email"    /> 
    Your Message 
     <textarea cols="40" rows="10" name="Message">
     </textarea> 
     <input type="submit" value="Send" /> 
     <input type="hidden" name="recipient" value="[email protected]" />
    <input type="hidden" name="subject" value="Subject" />
    <input type="hidden" name="redirect"  value="https://www.example.com/thanks.html" />
    <input type="hidden" name="missing_fields_redirect"  value="https://www.example.com/error.html" />
    <input type="hidden" name="required" value="realname,email,Message" />

</form>

phpMailer

How to use phpMailer to send emails from a webpage

PHP mail() function:

Using the PHP Mail() Function to send emails from a webpage

What script should I choose?

If you are creating a, “Contact Us” type of page, you may want to look into using FormMail. FormMail is configured to send to the same email address every time, and is a simple script to setup.

If the email address you need to send to is a different email address every time, for example a user has signed up for something on your website and needs a confirmation email, you should look into using either phpMailer or the php mail() function. Both of these scripts can be used within php, and this is very useful if the email address you need to email is gathered from a variable in your php script.

The phpMailer script can work on any of our servers, however due to current SPAM standards involved with the PHP ‘nobody’ user, the php mail() function is not enabled on all of our servers. All of our newer shared servers have the php mail() function enabled, however it is not enabled on some of our previous servers. Please contact the support department if you are unsure whether your server has the php mail() function enabled.

33 thoughts on “How to Send Email from a Web Page

  1. How do you send an entire forms contents with formatting and allow the user to, similar to Outlook or GMail?

    1. Depends on your form and the format of your email. When Gmail or Outlook displays a form, it’s using HTML code. If it’s using only a text format, then form won’t display on either of those email clients. If you want to learn more about displaying an HTML form in an HTML email, check out this post.

  2. Hi there,

    I am just wondering how i can embed a form into a wordpress site that allows a user send a link to a third party by entering in their email address.

    For clarity – a user enters in the email address of their real estate agent and then the form emails that address our link

    i appreciate the need for captcha elements and can code the form hidden fields etc – i am just wondering if this can even be done as a pop up using your script

    thanks

  3. Hi,

    Im having a single page website. I need to trigger mail in contact us form. Is it possible to do with Phb or node.js with nor shared hosting option without VPS ?. Thanks in advance.

    1. Yes, you can use PHP on the shared server environment. However, node.js is not available in that environment a VPS would be required for that. I hope this helps! Let us know if you have any further questions.

    1. We are happy to help, but it is not clear what you want to accomplish. Could you provide more details and examples so we can guide you further?

      Thank you,
      John-Paul

  4. Can any one please specify how to send emails from domain, and what are the things needed sending emails, if that happens how many we can send emails, can it be inboxed or it will be going to spam.

    Thanks in Advance

  5. Sir,

    I got a task that when a customer visiting my webpage he may put comment .  this comment must automatically send to admin mail account.

    Thankyou

    1. Are you using a content management system like WordPress? How are you comments being handled? We need more information before we can attempt to help you with the question.

    2. I have been using CGIEmail for the past 7 years to send email from a web page, and was recently told this is not longer supported. I am currently looking at other options. Someone suggested I try FormMail, but I do not see any way to format the email. Is there any chance you will support CGIEmail again?

    3. I spent some time looking into this and it seems like cgiemail is no longer being supported by its creators. This means it is not actively being updated and issues are not being addressed. This means it will become less compatible with the latest internet technology as time goes on.

      If you are building a full website with a contact form, I recommend using BoldGrid with WordPress. You can easily select a prebuilt form in BoldGrid. And since it is powered by WordPress, security vulnerabilities are addressed in their regular updates.

      Thank you,
      John-Paul

  6. sir,

    pls help me to link my webpage to gmail. when a visitor vistes my webpage and he put a comment then that comment need to send the admins gmail account automatically.

  7. What are chances of bulk maik to spam, can you please decsribe how to send mail to customer without spam because today google fetching side and make sites spamy.

     

    How to avoid while sending mails.

     

     

    Thanks & Regards

     

    1. Hello Shyamji,

      I would suggest watching what words you choose to put in your emails as if Google finds anything such as pills or anything that is severely common it will mark it as spam. Also please make sure you are authenticating with your outgoing mail server as that will help. Please also keep in mind that if you use DKIM and SPF records it helps provide legitimacy to your emails.

      Best Regards,
      TJ Edens

  8. Hello. Cool artcile

    My Question: I’m trying to implement a system where users can recieve daily or weekly email updates after signing up on my website. How do i implemet this?

    1. Hello Herlock,

      You may want to create a newletter type feature. There are many different programs out there that can handle this for you. One of the most popular is PHPList, which can be installed via the Softaculous installer tool.

      Kindest Regards,
      Scott M

    1. Hello Kirit,

      This article guides you on how to begin setting up a page or form that sends and email. We are unable to provide custom solutions at this time, however.

      Kindest Regards,
      Scott M

  9. If you have a PHP site and need free and easy open-source solution, then DPOST (
    https://sourceforge.net/projects/dpost/) may help.

    This is a template based e-vent emailing especially good for PHP, but may also be used by other sites in your company/domain, .Net, Java friendly.

    And it is free.

    1. Hello Peter,

      Thanks for the reply and the suggestion Peter! Here’s the link that you provided again since it’s not popping up as a clickable link in your post above:

      DPOST

      Kindest regards,
      Arnel C.

    2. Hello Moses,

      It is indeed a very nice setup. That site is a WordPress site so that entire contact area for social media and email is likely a plugin of sorts. We don’t currently develop in that area or make custom coded php solutions, but I will definitely place that on a list of potential projects to see if it is something we may be able to develop for a general site for a future article.

      Kindest Regards,
      Scott M

    1. Hello Kirit,

      I am unsure what you are asking. The three methods described and linked above are the methods of sending an email via a webpage. You will want to click on those links and read the additional information. If you have a specific question about the information, we are happy to assist you.

      Kindest Regards,
      Scott M

    1. Hello nealson,

      Thank you for contacting us. I am not exactly sure what you are asking, but here are all the links for within this page:

      Formmail: https://www.inmotionhosting.com/support/email/send-email-from-a-page/how-to-set-up-formmail

      phpMailer: https://www.inmotionhosting.com/support/email/send-email-from-a-page/using-phpmailer-to-send-mail-through-php

      PHP mail() function: https://www.inmotionhosting.com/support/website/sending-email-from-site/using-the-php-mail-function-to-send-emails

      If you have any further questions, feel free to post them below.
      Thank you,

      -John-Paul

Was this article helpful? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X