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)")