transpolymer commited on
Commit
bba110f
Β·
verified Β·
1 Parent(s): b9a26cf

Upload contact.py

Browse files
Files changed (1) hide show
  1. contact.py +55 -0
contact.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import smtplib
3
+ from email.mime.text import MIMEText
4
+
5
+ # Function to send email
6
+ def send_email(name, user_email, message):
7
+ email_sender = st.secrets["gmail"]["email"]
8
+ email_password = st.secrets["gmail"]["app_password"]
9
+ email_receiver = email_sender
10
+
11
+ subject = f"New Contact Form Message from {name}"
12
+ body = f"Name: {name}\nEmail: {user_email}\n\nMessage:\n{message}"
13
+
14
+ msg = MIMEText(body)
15
+ msg["Subject"] = subject
16
+ msg["From"] = user_email
17
+ msg["To"] = email_receiver
18
+
19
+ try:
20
+ server = smtplib.SMTP("smtp.gmail.com", 587)
21
+ server.starttls()
22
+ server.login(email_sender, email_password)
23
+ server.sendmail(user_email, email_receiver, msg.as_string())
24
+ server.quit()
25
+ return True
26
+ except Exception as e:
27
+ st.error(f"❌ Error sending email: {e}")
28
+ return False
29
+
30
+ # UI
31
+ def show():
32
+ st.title("πŸ“ž Contact Us - TransPolymer")
33
+ st.write("We're here to help! Please use the form below to contact us.")
34
+
35
+ col1, col2 = st.columns(2)
36
+
37
+ with col1:
38
+ st.subheader("πŸ“¬ Contact Form")
39
+ name = st.text_input("Name")
40
+ user_email = st.text_input("Your Email")
41
+ message = st.text_area("Message")
42
+
43
+ if st.button("πŸ“¨ Submit"):
44
+ if name and user_email and message:
45
+ if send_email(name, user_email, message):
46
+ st.success("βœ… Message sent! We’ll reply to your email soon.")
47
+ else:
48
+ st.error("❌ Failed to send. Please try again.")
49
+ else:
50
+ st.warning("⚠️ Fill in all fields.")
51
+
52
+ with col2:
53
+ st.subheader("πŸ“Œ Contact Information")
54
+ st.write("*TransPolymer Project Team*")
55
+ st.markdown("[πŸ“§ transpolymer2@gmail.com](mailto:transpolymer2@gmail.com)")