File size: 1,882 Bytes
bba110f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import smtplib
from email.mime.text import MIMEText

# Function to send email
def send_email(name, user_email, message):
    email_sender = st.secrets["gmail"]["email"]
    email_password = st.secrets["gmail"]["app_password"]
    email_receiver = email_sender

    subject = f"New Contact Form Message from {name}"
    body = f"Name: {name}\nEmail: {user_email}\n\nMessage:\n{message}"

    msg = MIMEText(body)
    msg["Subject"] = subject
    msg["From"] = user_email
    msg["To"] = email_receiver

    try:
        server = smtplib.SMTP("smtp.gmail.com", 587)
        server.starttls()
        server.login(email_sender, email_password)
        server.sendmail(user_email, email_receiver, msg.as_string())
        server.quit()
        return True
    except Exception as e:
        st.error(f"❌ Error sending email: {e}")
        return False

# UI
def show():
    st.title("πŸ“ž Contact Us - TransPolymer")
    st.write("We're here to help! Please use the form below to contact us.")

    col1, col2 = st.columns(2)

    with col1:
        st.subheader("πŸ“¬ Contact Form")
        name = st.text_input("Name")
        user_email = st.text_input("Your Email")
        message = st.text_area("Message")

        if st.button("πŸ“¨ Submit"):
            if name and user_email and message:
                if send_email(name, user_email, message):
                    st.success("βœ… Message sent! We’ll reply to your email soon.")
                else:
                    st.error("❌ Failed to send. Please try again.")
            else:
                st.warning("⚠️ Fill in all fields.")

    with col2:
        st.subheader("πŸ“Œ Contact Information")
        st.write("*TransPolymer Project Team*")
        st.markdown("[πŸ“§ transpolymer2@gmail.com](mailto:transpolymer2@gmail.com)")