简体   繁体   English

JavaScript是否可以通过单击按钮但不使用mailto:或表单操作来发送电子邮件?

[英]Can JavaScript send an email by clicking a button but NOT using mailto: or a form action?

I need to send an email from a server side script without loading a new page (which a form action would do). 我需要从服务器端脚本发送电子邮件而不加载新页面(表单操作会执行此操作)。 I have tried with XMLHttpRequest and some code I found somewhere: 我已经尝试过XMLHttpRequest和一些在某处找到的代码:

UniAjax.request({
    uri: 'sendMail.php',
    method: 'post',
    arguments: {
        bodysHTML: document.body.innerHTML
    }
});

But neither of them worked. 但是他们两个都不起作用。 Does anyone have any ideas? 有人有什么想法吗?

I do not know the action of form you are using is in same page or other page.php. 我不知道您正在使用的表单操作是在同一页面还是其他page.php中。

In both the case after sending mail ie after mail function if the mail has been sent properly you can specify header to redirect the page. 在这两种情况下,发送邮件后,即在发送邮件后,如果邮件已正确发送,您都可以指定标题来重定向页面。

$sentmail=mail($to, $subject, $message, $header);

if($sentmail)
{
header('Location: http://www.example.com/');
}

If u don't want the page to load only when u submit form, have a look at - http://jquery.malsup.com/form/ 如果您不希望仅在提交表单时加载页面,请查看-http://jquery.malsup.com/form/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JS或JQUERY但不使用MAILTO发送电子邮件 - How to send an email using JS or JQUERY but no MAILTO 如何创建一个Mailto共享按钮,该按钮会打开一个窗口,用户可以在其中输入要发送到的电子邮件地址 - How to Create a Mailto Share Button that Opens a Window in which Ones Can Enter Email Address to Send to 从表单字段(电子邮件,密码)中获取和存储数据,而无需用户使用Angular,Javascript单击按钮 - Fetching and storing data from form fields (email, password) without user clicking a button using Angular, Javascript 是否可以仅使用Javascript发送电子邮件而不必单击电子邮件客户端上的“发送”按钮? - Can I Send an Email using ONLY Javascript Without Having to Click The Send Button on the Email Client? 在iFrame中使用JavaScript单击表单按钮 - Clicking Form Button using JavaScript inside an iFrame 无法发送 email 并且单击提交按钮时始终刷新 - Can't send email and upon clicking the submit button always refreshing 使用mailto(JavaScript)发送电子邮件-更改邮件正文中特定字符的字体大小或将其设置为粗体 - Send email using mailto (JavaScript) — change the font size of the specific characters inside the mail body or make it BOLD 发送带有无表单按钮的电子邮件 - Send an email with a button with no form 如何在不单击 Javascript 的按钮的情况下触发操作? - How can I trigger an action without clicking a button with Javascript? 如何使用Java的:: mailto验证表单并发送输入值? - How do I validate form and send input values with ::mailto with Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM