利用javascript发送邮件

我们在做web应用程序时,有时客户希望发送邮件,这时我们可以用jmail结合javascript发送邮件.具体做法如下:
将jmail  dll文件添加到项目中,然后在head中添加如下脚本函数就ok

/*
**infor: 要发送的邮件信息
**subject:  要发送的邮件主题
*/
function SendEMail(infor, subject)
{
    var jMail = new ActiveXObject("Jmail.message");    
    jMail.Silent = true;
    jMail.Charset = "gb2312";   
    jMail.FromName = "sender"    //发件人
    jMail.From = "
sender@163.com ";   //发送人的邮件地址
    jMail.AddRecipient("
accepter@163.com ");  //收件人的邮件地址
    jMail.Subject = subject;
    jMail.Body = infor;    
    jMail.MailServerUserName="发件人邮箱登陆名";
    jMail.MailServerPassWord="发件人邮箱登陆密码";       
    var ret = jMail.Send("smtp.163.com");   
    if(ret == false)
    {
        alert("fail");
    }
    else
    {
        alert("success");
    }
    jMail.Close();
   
}
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个简单的HTML5 + CSS3 + JavaScript个人网页的示例代码,可以作为参考: HTML代码: ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>个人网页</title> <link rel="stylesheet" href="style.css"> </head> <body> <header> <h1>个人网页</h1> <nav> <ul> <li><a href="#about">关于我</a></li> <li><a href="#portfolio">作品集</a></li> <li><a href="#contact">联系我</a></li> </ul> </nav> </header> <main> <section id="about"> <h2>关于我</h2> <p>我是一名前端开发工程师,热爱技术和设计。</p> </section> <section id="portfolio"> <h2>作品集</h2> <ul> <li> <img src="portfolio-1.jpg" alt="作品1"> <h3>作品1</h3> <p>作品1的介绍</p> </li> <li> <img src="portfolio-2.jpg" alt="作品2"> <h3>作品2</h3> <p>作品2的介绍</p> </li> <li> <img src="portfolio-3.jpg" alt="作品3"> <h3>作品3</h3> <p>作品3的介绍</p> </li> </ul> </section> <section id="contact"> <h2>联系我</h2> <form> <label for="name">姓名:</label> <input type="text" id="name" name="name" required> <label for="email">邮箱:</label> <input type="email" id="email" name="email" required> <label for="message">留言:</label> <textarea id="message" name="message"></textarea> <button type="submit">发送</button> </form> </section> </main> <footer> <p>©2021 个人网页</p> </footer> <script src="script.js"></script> </body> </html> ``` CSS代码: ``` body { font-family: Arial, sans-serif; margin: 0; padding: 0; } header { background-color: #333; color: #fff; display: flex; justify-content: space-between; padding: 20px; } nav ul { list-style: none; margin: 0; padding: 0; } nav ul li { display: inline-block; } nav ul li a { color: #fff; display: block; padding: 10px; text-decoration: none; } main { padding: 20px; } section { margin-bottom: 40px; } section h2 { font-size: 36px; margin-bottom: 20px; } section ul { list-style: none; margin: 0; padding: 0; } section ul li { margin-bottom: 20px; } section ul li img { max-width: 100%; } section ul li h3 { font-size: 24px; margin-bottom: 10px; } section ul li p { font-size: 16px; } form label { display: block; font-size: 18px; margin-bottom: 10px; } form input[type="text"], form input[type="email"], form textarea { border: 1px solid #ccc; font-size: 16px; padding: 10px; width: 100%; } form button[type="submit"] { background-color: #333; border: none; color: #fff; cursor: pointer; font-size: 18px; margin-top: 10px; padding: 10px; } footer { background-color: #333; color: #fff; padding: 20px; text-align: center; } ``` JavaScript代码: ``` // 为导航栏添加滚动效果 const navLinks = document.querySelectorAll('nav ul li a'); for (const link of navLinks) { link.addEventListener('click', e => { e.preventDefault(); const section = document.querySelector(link.getAttribute('href')); section.scrollIntoView({behavior: 'smooth'}); }); } // 验证表单并发送邮件 const form = document.querySelector('form'); form.addEventListener('submit', e => { e.preventDefault(); const name = document.querySelector('#name').value.trim(); const email = document.querySelector('#email').value.trim(); const message = document.querySelector('#message').value.trim(); if (name === '' || email === '' || message === '') { alert('请输入姓名、邮箱和留言内容'); return; } // 发送邮件的代码 }); ``` 以上代码仅作为示例,实际网页开发需要根据具体需求和目标进行调整和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值