Talking about the practical application of html mailto (email)

Talking about the practical application of html mailto (email)
As we all know, mailto is a very practical HTML tag in web design and production. Many friends who have personal web pages like to write their email addresses in a conspicuous position on the website, so that once the web browser clicks the hyperlink composed of mailto with the mouse, it can automatically open the default email client software in the current computer system, such as OutLook Express and Foxmail.

However, due to the inconsistency between the operating systems and mail clients in handling mailto event connections, you need to be careful when using it in practice;

1. Basic grammar

<a href=mailto:[email protected]>send email</a>

or

<form action="mailto:[email protected]">

</form>

Parameter list:

to Recipients (separate multiple recipients with ;)
suject theme
cc Cc
bcc Blind copy
body Content (some email clients support HTML format statements)

The parameter transfer method is the same as the value transfer between pages. You can use a link string or a form

Connection String

<a href="mailto:[email protected]?subject=testtitle&[email protected]&body=this is body">send mail</a>

Form

Copy code
The code is as follows:

<form name='sendmail' action='mailto:[email protected]'>
<input name='cc' type='text' value='[email protected]'>
<input name='subject' type='text' value='testtitle'>
<input name='body' type='text' value='this is body'>
</form>

2. Differences between email clients

The above is a simple syntax application of mailto; however, in actual application, different browser clients may have different effects depending on the browser settings.

Especially when the body content contains HTML format statements, you need to pay attention to this;

Outlook displays the HTML statements in the body as they are (even if the HTML in the body is escaped, it is still invalid). So what should we do if we want to wrap the statements in the body when using Outlook Mailto? <br/> has no effect. . The %0D character is required as a line break symbol;

Foxmail will display the corresponding HTML effect of the HTML statement in the body;

Of course, you can also use another method to implement the mailto type client to send emails:

Copy code
The code is as follows:

function SendMail(filePath) {
var path = location.href.substring(0, location.href.lastIndexOf("/")) + filePath;
var outlookApp = new ActiveXObject("Outlook.Application");
var nameSpace = outlookApp.getNameSpace("MAPI");
var mailItem = outlookApp.CreateItem(0);
var mailto = "[email protected]";
var mailBody= "<HTML><BODY><DIV><FONT color='red'>test this is body html</FONT></DIV></BODY></HTML>";
mailItem.Subject = "test title";
mailItem.To = mailto;
mailItem.HTMLBody = mailBody;
if (path != "") {
mailItem.Attachments.Add(path);
}
mailItem.Display(0);
mailItem = null;
nameSpace = null;
outlookApp = null;
}

But this has a big disadvantage: it only supports Outlook clients, and requires the configuration of Internet options, and "Initialize and script ActiveX controls not marked as safe" must be enabled.

Calling mailItem's Attachments.Add is to add attachments to the email. If there is no attachment, the filePath parameter can be deleted.

If you need to add a carbon copy object, you can call mailItem.Cc. If you need to add a blind copy object, you can call mailItem.Bcc.

<<:  The "3I" Standards for Successful Print Advertising

>>:  Basic reference types of JavaScript advanced programming

Recommend

How to modify the root password of mysql under Linux

Preface The service has been deployed on MySQL fo...

Linux super detailed gcc upgrade process

Table of contents Preface 1. Current gcc version ...

How to quickly build an FTP file service using FileZilla

In order to facilitate the storage and access of ...

How to use Tencent slider verification code in Vue3+Vue-cli4 project

Introduction: Compared with traditional image ver...

Implementation of Docker to build Zookeeper&Kafka cluster

I've been learning Kafka recently. When I was...

Detailed explanation of four types of MySQL connections and multi-table queries

Table of contents MySQL inner join, left join, ri...

CSS3 achieves various border effects

Translucent border Result: Implementation code: &...

About 3 common packages of rem adaptation

Preface I wrote an article about rem adaptation b...

The whole process record of Vue export Excel function

Table of contents 1. Front-end leading process: 2...

Native javascript+CSS to achieve the effect of carousel

This article uses javascript+CSS to implement the...

Explanation of Dockerfile instructions and basic structure

Using Dockerfile allows users to create custom im...

CSS3 implements the sample code of NES game console

Achieve resultsImplementation Code html <input...

HTML table tag tutorial (17): table title vertical alignment attribute VALIGN

The table caption can be placed above or below th...