ReySajju742 commited on
Commit
837052b
·
verified ·
1 Parent(s): ca49885

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, redirect, url_for, flash
2
+ import requests
3
+ import os
4
+
5
+ app = Flask(__name__)
6
+ app.secret_key = 'your_secret_key' # Change this to a random secret key
7
+
8
+ # Set up your Brevo API key
9
+ BREVO_API_KEY = "xsmtpsib-9f5b29b661acc0243d2132c93d8ab4024cce4f3011b41a29e72744e21c1ce45b-B1HmQjL72G36FcKS"
10
+
11
+ def send_email_via_brevo(to_email, subject, body):
12
+ url = "https://api.brevo.com/v3/smtp/email"
13
+ headers = {
14
+ "accept": "application/json",
15
+ "content-type": "application/json",
16
+ "api-key": BREVO_API_KEY
17
+ }
18
+ data = {
19
+ "sender": {"name": "Your Name", "email": "remproduction786@gmail.com"},
20
+ "to": [{"email": to_email}],
21
+ "subject": subject,
22
+ "textContent": body
23
+ }
24
+ response = requests.post(url, headers=headers, json=data)
25
+ return response.status_code, response.json()
26
+
27
+ @app.route('/')
28
+ def home():
29
+ return render_template('contact_form.html')
30
+
31
+ @app.route('/send', methods=['POST'])
32
+ def send_email():
33
+ first_name = request.form['firstName']
34
+ last_name = request.form['lastName']
35
+ email = request.form['email']
36
+ event_type = request.form['eventType']
37
+ event_details = request.form['eventDetails']
38
+
39
+ # Construct the email content
40
+ subject = 'New Contact Form Submission'
41
+ body = f'''
42
+ New contact form submission:
43
+
44
+ First Name: {first_name}
45
+ Last Name: {last_name}
46
+ Email: {email}
47
+ Event Type: {event_type}
48
+ Event Details: {event_details}
49
+ '''
50
+
51
+ # Send the email using Brevo
52
+ status_code, response_data = send_email_via_brevo(
53
+ to_email="sajjadr742@gmail.com", # Admin email
54
+ subject=subject,
55
+ body=body
56
+ )
57
+
58
+ # Check the response status
59
+ if status_code == 201:
60
+ flash('Message sent successfully!', 'success')
61
+ else:
62
+ flash('Message could not be sent. Please try again later.', 'error')
63
+ print(response_data) # Print error details for debugging
64
+
65
+ return redirect(url_for('home'))
66
+
67
+ if __name__ == '__main__':
68
+ app.run(debug=True)