te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Need to Send Email from HTML pages - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Need to Send Email from HTML pages - Stack Overflow

programmeradmin3浏览0评论

I m creating a Website as Static HTML pages. In that only in one contacts page alone i need to get the users name and emailId . This information should be send to a particular mail Id with the information of username and emailId.

I m using only HTML and Javascript , can anyone say me how to make it possible.

I m creating a Website as Static HTML pages. In that only in one contacts page alone i need to get the users name and emailId . This information should be send to a particular mail Id with the information of username and emailId.

I m using only HTML and Javascript , can anyone say me how to make it possible.

Share Improve this question asked Nov 30, 2009 at 10:17 Fairy_GFairy_G 4173 gold badges12 silver badges23 bronze badges 0
Add a ment  | 

5 Answers 5

Reset to default 7

Without any backend stuff your only option is using a mailto in an href. This relies on the user sending the email themselves. You might be able to do something with javascript to populated the email .e.g

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

You can send yourself the form data by using the following html:

<form method="post" action="mailto:[email protected]?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>

Clicking on submit will create a new email message with the default mail client and will populate the subject Results and the body with the form data which will look like this

Name=PJP&Email=me%40my. 

Note how the data has been url encoded. e.g. %40 for the @ sign.

The user will have to press Send to send the message.

I used to do something similar to this around 15 years ago before I discovered a cgi-bin sendMail script on my old webhost.

Any reason you can't use server-side code? This kind of thing is very easily doable with PHP. Otherwise, the only choice is the <a href="mailto .. as pointed out already.

If you really can't use PHP, you can use the formmail.cgi if your host provides one. Most hosts support this, and instructions for using FormMail are simple.

This is trivial if you are using PHP though. You can try to rename the page with a .php extension (instead of .htm or .html) and put the following code into your page:

        <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("[email protected]", "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>

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

You can Send an email using only JavaScript. No server-side languages involved.

发布评论

评论列表(0)

  1. 暂无评论