smtplib.SMTPSenderRefused: (555, b'5.5.2 Syntax error. c13-

Viewed 21

smtplib.SMTPSenderRefused: (555, b'5.5.2 Syntax error. c13-20020a170903234d00b0016f85feae65sm13557182plh.87 - gsmtp', 'email@email.com')

I am trying to have a contact form where someone can write a message to me and it get sent to my email while they get an email response that their message was sent. Everything works until I try to get to the server.sendmail side of things. (the form works, the route works), but I am getting an error code.

The problem seems to come when I try to have subject in there. is there a way I can send the email with a subject? or should I just leave it off?

Here is my html form:

 <form action="/thank-you" method="POST"> 
        <div>
            <select name="subject" id="subject">What is this message about?
                <option value="Bible">Bible</option>
                <option value="Spiritual Things">Spiritual Things</option>
                <option value="Website">Website</option>
                <option value="Just to Talk">Just to talk</option>
                <option value="Other">Other</option>
            </select>
        </div>
        <br><br>
        <div>
            <input type="text" id="first_name" name="first_name" placeholder="First Name" required>
        </div>
        <br>
        <div>
            <input type="text" id="last_name" name="last_name" placeholder="Last Name">
        </div>
        <br>
        <div>
            <input type="text" id="email" name="email" placeholder="sample@email.com" required>
        </div>
        <br>

        <div>
            <input type="text" id="message" name="message" placeholder="Write your message here." required>
        </div>

        <br>

        <div>
            <input type="reset">
        </div>

        <br>

        <div>
            <input type="submit">
            <br><br><br>
        </div>

    </form> 

Here is my route

@views.route('/thank-you', methods = ['POST'])
def thank_you():
    subject = request.form.get("subject")
    first_name = request.form.get("first_name")
    last_name = request.form.get("last_name")
    email = request.form.get("email")
    message = request.form.get("message")

    response_message = "Thank you for contacting me."

    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    server.login("email@email.com", "Email_PW"])
    server.sendmail("email@email.com", email, subject, response_message)
    server.sendmail("email@email.com", "email@email.com", subject, first_name, last_name, email, message)


    title = "Thank You"
    return render_template('thank_you.html', title=title, subject=subject, first_name=first_name, last_name=last_name, email=email, message=message)  

any ideas?

0 Answers
Related