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 address in a prominent position on the website, so that once the web browser clicks with the mouse, After the super connection formed by mailto, the default email client software in the current computer system can be automatically opened, such as OutLook Express and Foxmail.
However, since various operating systems and mail clients handle mailto event connections inconsistently, you need to pay attention when applying them in practice;
1. Basic syntax
send email
or
Parameter list:
to |
收信人(多个之间用;分割) |
suject |
主题 |
cc |
抄送 |
bcc |
暗抄送 |
body |
内容(部分邮件客户端支持html格式语句) |
The method of passing parameters is the same as passing values between pages. You can use link strings or form
link string
send mail form method
2. Mail client differences The above is a simple syntax application of mailto; but in actual application, depending on the browser client settings of the browser, there will be different effects;
Especially when the body content contains statements in html format, this You need to pay attention when doing so;
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 statements in the body when doing Outlook mailto?
has no effect. . Need to use
character as a newline symbol;
foxmail will display the corresponding html effect of the html statement of the body;
Of course, you can also use another way to implement a mailto-type client to send emails:
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 = "test@163.com ";
var mailBody= "
test this is 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: only To support the Outlook client, you need to configure the Internet options and enable "Initialize and script run ActiveX controls not marked as safe".
The Attachments.Add of mailItem is called to add attachments to the email. When there are no attachments, the filePath parameter can be deleted.
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.