Email must be sent from HTML pages

I am creating a website as static HTML pages. In this, on only one contact page, I need to get the username and emailId. This information should be sent to a specific mail identifier with information about the username and emailId.

I use only HTML and Javascript, can anyone tell me how to make this possible.

+3
source share
5 answers

Without any backend files, your only option is to use mailto in href. It depends on who sends the email on their own. You might be able to do something with javascript to populate .eg email

"mailto:"+emailTo+"&subject="+subjectText+"&body="+bodyText
+7

, html:

<form method="post" action="mailto:me@my.com?subject=Results">

    <label for="Name">Name:</label><input type="text" name="Name"><br />
    <label for="Email">Email:</label><input type="text" name="Email"><br />
    <input type="submit">
    </form>
Hide result

submit, Results , :

Name=PJP&Email=me%40my.com 

, URL. %40 @.

"", .

- 15 , cgi-bin sendMail script -.

+2

? PHP. <a href="mailto.. .

+1

PHP, formmail.cgi, . , FormMail .

, PHP. .php( .htm .html) :

        <div class="post">
        <h2 class="title">Write to us</h2>
        <?php
        function validEmail($email)
        {
            $isValid = true;
            $atIndex = strrpos($email, "@");
            if (is_bool($atIndex) && !$atIndex)
            {
                $isValid = false;
            }
            else
            {
                $domain = substr($email, $atIndex+1);
                $local = substr($email, 0, $atIndex);
                $localLen = strlen($local);
                $domainLen = strlen($domain);
                if ($localLen < 1 || $localLen > 64)
                {
                    // local part length exceeded
                    $isValid = false;
                }
                else if ($domainLen < 1 || $domainLen > 255)
                {
                    // domain part length exceeded
                    $isValid = false;
                }
                else if ($local[0] == '.' || $local[$localLen-1] == '.')
                {
                    // local part starts or ends with '.'
                    $isValid = false;
                }
                else if (preg_match('/\\.\\./', $local))
                {
                    // local part has two consecutive dots
                    $isValid = false;
                }
                else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
                {
                    // character not valid in domain part
                    $isValid = false;
                }
                else if (preg_match('/\\.\\./', $domain))
                {
                    // domain part has two consecutive dots
                    $isValid = false;
                }
                else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                            str_replace("\\\\","",$local)))
                {
                    // character not valid in local part unless 
                    // local part is quoted
                    if (!preg_match('/^"(\\\\"|[^"])+"$/',
                        str_replace("\\\\","",$local)))
                    {
                    $isValid = false;
                    }
                }
                if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
                {
                    // domain not found in DNS
                    $isValid = false;
                }
            }
            return $isValid;
        }


        if (isset($_REQUEST['email']))
          {//if "email" is filled out, proceed

          //check if the email address is invalid
          $mailcheck = validEmail($_REQUEST['email']);
          if ($mailcheck==FALSE)
            {
            echo "<p>Invalid e-mail address.</p>";
            }
          else {
            //send email
            $name = $_REQUEST['name'] ;
            $email = $_REQUEST['email'] ;
            $message = $_REQUEST['message'] ;
            mail("recepient@example.com", "Subject: Message from contact form",
            $message, 'From: "' . $name . '" <' . $email . '>' );
            echo "<p>Thank you for writing to our website. Please allow up to 24 hours for a reply, if you have requested one.</p>";
            }
          }
        else {
          //if "email" is not filled out, display the form
          echo "<form method='post' action='contact.php'>
          Name: <input id='name' name='name' type='text' /><br />
          E-mail: <input id='email' name='email' type='text' /> (required)<br />
          Message for us:<br />
          <textarea id='message' name='message' rows='15' cols='40'>
          </textarea><br />
          <input id='submit' type='submit' value='Send Message' />
          </form>";
          }
        ?>
    </div>
0

Refer - https://medium.com/design-startups/b53319616782

You can send an email using only JavaScript. Server languages ​​are not involved.

0
source

Source: https://habr.com/ru/post/1724273/


All Articles