Spaces:
Running
Running
File size: 2,206 Bytes
a55a905 67ef359 a6c86e3 67ef359 a6c86e3 33dbc5c a6c86e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import streamlit as st
import streamlit.components.v1 as components
def show():
st.title("📬 Contact Us")
st.write("Feel free to reach out to us by filling the form below.")
public_key = st.secrets["emailjs"]["public_key"]
service_id = st.secrets["emailjs"]["service_id"]
template_id = st.secrets["emailjs"]["template_id"]
with st.form(key="contact_form"):
name = st.text_input("Your Name")
email = st.text_input("Your Email")
message = st.text_area("Your Message")
submit_button = st.form_submit_button("Send")
if submit_button:
if name and email and message:
st.success("Sending your message...")
js_code = f"""
var templateParams = {{
name: "{name}",
email: "{email}",
message: `{message}`
}};
emailjs.send("{service_id}", "{template_id}", templateParams, "{public_key}")
.then(function(response) {{
console.log("SUCCESS!", response.status, response.text);
window.parent.postMessage({{"type": "success", "message": "Email sent successfully!"}}, "*");
}}, function(error) {{
console.log("FAILED...", error);
window.parent.postMessage({{"type": "error", "message": "Failed to send email."}}, "*");
}});
"""
components.html(f"""
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/emailjs-com@2.6.4/dist/email.min.js"></script>
<script>
(function() {{
emailjs.init("{public_key}");
{js_code}
}})();
</script>
</head>
<body></body>
</html>
""", height=0)
# Call the function to display the contact form
show()
|