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
This article introduces the installation and use ...
After installing VMware Tools, ① text can be copi...
Encryption and decryption are an important means ...
Table of contents cycle for for-in for-of while d...
Preface The project has requirements for charts, ...
Preface This article mainly introduces the releva...
When I first used docker, I didn't use docker...
Table of contents 1. Introduction 2. Detailed exp...
Table of contents The effect of mixed inheritance...
Mysql is a mainstream open source relational data...
Demand background Part of the data in the busines...
I don’t know if you have ever encountered such a ...
Installing XML extension in PHP Linux 1. Enter th...
Before talking about the structural markup of web...
1. Implementation principle of Nginx load balanci...