[英]How can I get specific data from firebase database which key value is e-mail?
[英]E-mail a value which is returned by a function
我想知道是否可以 email 一個由 javascript 中的 function 返回的值? 還是我必須使用 php/ajax?
從下面的例子中,我想把 email abc 給自己? 怎么做到呢?
<html>
<head><script>
var t = "abc";
function test(){
return t;}
</script></head>
<body onload = "test()">
</body></html>
您需要通過 XHR 將其發布到您的服務器,然后您的服務器可以 email 它。
沒有直接的方法。 我會使用 jQuery 的$.post將相關信息發布到 PHP 頁面,然后使用最簡單的命名郵件function 將其郵寄。
在主頁的腳本標記之一或單獨的 .js 文件中:
$.post("mailer.php", {data: "abc"}, function(data) {
// Alert yourself whether it was successful if you want
});
和 mailer.php (用您自己的值替換這些):
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = $_POST['data'];
$headers = 'From: webmaster@example.com';
mail($to, $subject, $message, $headers);
?>
這是另一個類似問題的一個很好的解釋:
您不能使用 javascript 發送 email ,您可以獲得的最接近的將是打開默認 email 客戶端的 mailto - 但不會發送任何內容。
Email 應該從服務器發送 - 以正常方式提交表單,並在服務器上構造 email 並發送它....
那里的另一個答案提供了有關使用mailto
的一些詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.