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

Detailed explanation of Javascript basics loop

Table of contents cycle for for-in for-of while d...

CSS polar coordinates example code

Preface The project has requirements for charts, ...

Docker modifies the configuration information of an unstarted container

When I first used docker, I didn't use docker...

A simple and in-depth study of async and await in JavaScript

Table of contents 1. Introduction 2. Detailed exp...

Detailed explanation of mixed inheritance in Vue

Table of contents The effect of mixed inheritance...

MySQL concurrency control principle knowledge points

Mysql is a mainstream open source relational data...

MySQL learning record: bloody incident caused by KEY partition

Demand background Part of the data in the busines...

Analysis of the process of building a LAN server based on http.server

I don’t know if you have ever encountered such a ...

Detailed steps to install xml extension in php under linux

Installing XML extension in PHP Linux 1. Enter th...

A brief discussion on the application of Html web page table structured markup

Before talking about the structural markup of web...