from flask import Flask, render_template, request, redirect, url_for, flash import requests import os app = Flask(__name__) app.secret_key = 'your_secret_key' # Change this to a random secret key # Set up your Brevo API key BREVO_API_KEY = "xsmtpsib-9f5b29b661acc0243d2132c93d8ab4024cce4f3011b41a29e72744e21c1ce45b-B1HmQjL72G36FcKS" def send_email_via_brevo(to_email, subject, body): url = "https://api.brevo.com/v3/smtp/email" headers = { "accept": "application/json", "content-type": "application/json", "api-key": BREVO_API_KEY } data = { "sender": {"name": "Your Name", "email": "remproduction786@gmail.com"}, "to": [{"email": to_email}], "subject": subject, "textContent": body } response = requests.post(url, headers=headers, json=data) return response.status_code, response.json() @app.route('/') def home(): return render_template('contact_form.html') @app.route('/send', methods=['POST']) def send_email(): first_name = request.form['firstName'] last_name = request.form['lastName'] email = request.form['email'] event_type = request.form['eventType'] event_details = request.form['eventDetails'] # Construct the email content subject = 'New Contact Form Submission' body = f''' New contact form submission: First Name: {first_name} Last Name: {last_name} Email: {email} Event Type: {event_type} Event Details: {event_details} ''' # Send the email using Brevo status_code, response_data = send_email_via_brevo( to_email="sajjadr742@gmail.com", # Admin email subject=subject, body=body ) # Check the response status if status_code == 201: flash('Message sent successfully!', 'success') else: flash('Message could not be sent. Please try again later.', 'error') print(response_data) # Print error details for debugging return redirect(url_for('home')) if __name__ == '__main__': app.run(debug=True)