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:
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
Use the Linux utility certbot to generate https c...
Preface The service has been deployed on MySQL fo...
Table of contents Preface 1. Current gcc version ...
In order to facilitate the storage and access of ...
Introduction: Compared with traditional image ver...
I believe that everyone needs to reinstall MySQL ...
I've been learning Kafka recently. When I was...
Table of contents MySQL inner join, left join, ri...
Translucent border Result: Implementation code: &...
Preface I wrote an article about rem adaptation b...
Table of contents 1. Front-end leading process: 2...
This article uses javascript+CSS to implement the...
Using Dockerfile allows users to create custom im...
Achieve resultsImplementation Code html <input...
The table caption can be placed above or below th...