Talking about the practical application of html mailto (e-mail)

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 prominent positions on the website, and when clicked, they can automatically open the current computer system. Default email client software, very helpful to be able to reach us
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 prominent positions on the website, so that once the web browser clicks with the mouse, the After the super connection composed of mailto, the default email client software in the current computer system, such as OutLook Express and Foxmail, can be automatically opened.

However, due to the inconsistent handling of mailto event connection between operating systems and mail clients, attention should be paid to the actual application;

1. Basic syntax

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

or  

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

</form>

Parameter list:

 

to recipients (used between multiple; split)
subject theme
cc cc
bcc Bcc
body Content (some email clients support html format statements)

 

The parameter passing method is the same as passing values ​​between pages. You can use a link string or a form

link string

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

form

copy code
code show as below:

<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 mail clients The

above is a simple syntax application of mailto; but in actual applications, depending on the browser client set by the browser, there will be no effect;

especially when the body content contains statements in html format, it is necessary to Note;

Outlook displays the html statement of the body as it is (it is also invalid after escaping the html of the body), so what should we do if we want to wrap the statement in the body when Outlook mailto? <br/> is ineffective. . The %0D character needs to be used as the newline symbol;

foxmail will display the corresponding html effect to the html statement of the body; of

course, another way can be used to realize the client of type mailto to send mail:

copy code
code show as below:

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 client, Internet options need to be configured, "initialize and run scripts for ActiveX controls that are not marked as safe" to be enabled.

The Attachments.Add of calling mailItem is to add attachments to the email. When there is no attachment, you can delete the filePath parameter.

If you need to add a CC object, you can call mailItem.Cc, if you need to add a CC object, you can call the mailItem.Bcc method.
 

Search " Script House " on WeChat Official Account and select Follow

Those things about programmers, sending books and other activities are waiting for you

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324804579&siteId=291194637