[英]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.