[英]Sender email address not included in EmailJS
When I submit the form, I receive the user's message.当我提交表单时,我会收到用户的消息。 However, I don't know who it's from.
但是,我不知道它来自谁。 I don't receive their email address, nor their name.
我没有收到他们的 email 地址,也没有他们的名字。 I tried looking at their documentation but wasn't able to get past this.
我尝试查看他们的文档,但无法克服这一点。 Any help will be appreciated.
任何帮助将不胜感激。 Thank you!
谢谢!
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/emailjs-com@2/dist/email.min.js"></script>
<script type="text/javascript">
(function () {
// https://dashboard.emailjs.com/admin/integration
emailjs.init("MY_USER_ID");
})();
</script>
<script type="text/javascript">
window.onload = function () {document.getElementById("contact-form").addEventListener("submit", function (event) {
event.preventDefault();
// generate a five digit number for the contact_number variable
this.contact_number.value = Math.random() * 100000 | 0;
// these IDs from the previous steps
emailjs.sendForm("MY_SERVICE_ID", "MY_TEMPLATE_ID", this).then(
function () {
console.log("SUCCESS!");
},
function (error) {
console.log("FAILED...", error);
}
);
});};
</script>
</head>
<body>
<form id="contact-form">
<input type="hidden" name="contact_number" />
<label>Name</label>
<input type="text" name="user_name" />
<label>Email</label>
<input type="email" name="user_email" />
<label>Message</label>
<textarea name="message"></textarea>
<input type="submit" value="Send" />
</form>
</body>
{{message}}
is the only thing you can receive from the form for now because your template has two dynamic variables {{from_name}}
, {{message}}
but you are sending contact_number
, user_name
, user_email
and message
which is written in name attributes for each inputs in the form. {{message}}
是您现在可以从表单中收到的唯一内容,因为您的模板有两个动态变量{{from_name}}
, {{message}}
但您发送的是contact_number
, user_name
, user_email
和message
表单中每个输入的名称属性。
You have to match names of template variables and names of form inputs.您必须匹配模板变量的名称和表单输入的名称。 If you want to maintain your form, you have to modify your template like
如果要维护表单,则必须修改模板,例如
from You got a new email from {{from_name}}: {{message}}
You got a new email from {{from_name}}: {{message}}
to You got a new email from {{user_name}}({{user_email}}): {{message}}
You got a new email from {{user_name}}({{user_email}}): {{message}}
You can also use built-in variables without getting input but I'll leave them because you need to read the documentation for good.您也可以在不获取输入的情况下使用内置变量,但我将保留它们,因为您需要永久阅读文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.