Forums

Contact us button

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)

Maybe add some debugging logging to inspect variables in the web app logs.

I have ML model running in my web app which is quite slow and takes time. How can I speed up the process, should I buy better package?

Maybe decouple it from the web app. See https://help.pythonanywhere.com/pages/AsyncInWebApps/