-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_form.py
More file actions
40 lines (31 loc) · 1.08 KB
/
process_form.py
File metadata and controls
40 lines (31 loc) · 1.08 KB
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
# process_contact_form.py
import cgi
import smtplib
def send_email(name, email, message):
# Configure email settings
sender_email = 'your_email@example.com'
receiver_email = 'recipient@example.com'
smtp_server = 'smtp.example.com'
smtp_port = 587
smtp_username = 'your_smtp_username'
smtp_password = 'your_smtp_password'
# Construct email message
subject = f'New Contact Form Submission from {name}'
body = f'Name: {name}\nEmail: {email}\nMessage: {message}'
message = f'Subject: {subject}\n\n{body}'
# Send email
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(smtp_username, smtp_password)
server.sendmail(sender_email, receiver_email, message)
# Main function to handle form submission
def main():
form = cgi.FieldStorage()
name = form.getvalue('name')
email = form.getvalue('email')
message = form.getvalue('message')
# Perform additional validation if needed
# Send email notification
send_email(name, email, message)
if __name__ == '__main__':
main()