I am trying to set up a contact button on my website which takes the information and forwards it to me in an e-mail. If I manually put values in for the subject/body of the e-mail and run it from the terminal it will successfully send an e-mail, but attempting collect information from the form so far has done nothing.
<title>Contact us!</title> <link rel="stylesheet" href="{{ url_for('static', filename='css/contact.css') }}"> <div class="container"> <form action="contact">
<label for="report">Reason</label>
<select id="report" name="report">
<option value="Bug">Bug</option>
<option value="Suggestion">Suggestion</option>
<option value="Other">Other</option>
</select>
<label for="Subject">Subject</label>
<textarea id="Subject" name="Subject" placeholder="Write something.." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form> </div>
And here is my python code
@app.route("/contact", methods=["GET", "POST"]) def feedback(): if request.method == 'GET': return render_template("contact.html") else: result = "Thanks for the feedback!" report = request.form['report'] Subject = request.form['Subject']
from email.mime.text import MIMEText
import smtplib
gmail_user = 'email@gmail.com'
gmail_password = 'password'
message = MIMEText(report)
message["Subject"] = Subject
message["From"] = gmail_user
message["To"] = gmail_user
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(gmail_user, gmail_user, message.as_string())
server.close()
return render_template('settlement_return.html',result = result)