I am writing python code using flask and html and I want to send an email to me via the site, an error appears that the method is not allowed code below
`from flask import Flask, render_template, request
import smtplib
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/order', methods=['POST'])
def process_order():
def send_email():
email = request.form['email']
message = request.form['message']
# Sending an email
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("rprp9**@gmail.com", "***")
server.sendmail("rprp9**[email protected]", email, message.encode('utf-8'))
server.quit()
return "The request has been sent successfully, you will be answered soon!"
if __name__ == '__main__':
app.run(debug=True)`
order.html below:
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="/order" method="post">
<input type="text" name="email" placeholder="Email"><br>
<textarea name="message" placeholder="Message"></textarea><br>
<input type="submit" value="Send">
</form>
</body>
</html>`
I tried many ways from the Internet, nothing helped.
New contributor
N1PEL is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.