I am stuck on CS50W's Project 3 Mail. I'm very new to JavaScript so I think I'm probably missing something obvious but I cannot get it to send an email. When I go to the admin section there's nothing there so it's not saving anything. I've tried many different things, but just can't get it to actually send the email.

inbox.js relevant code:

function compose_email() {

  // Show compose view and hide other views
  document.querySelector('#emails-view').style.display = 'none';
  document.querySelector('#compose-view').style.display = 'block';

  // Clear out composition fields
  document.querySelector('#compose-recipients').value = '';
  document.querySelector('#compose-subject').value = '';
  document.querySelector('#compose-body').value = '';


function load_mailbox(mailbox, template) {

document.querySelector('#compose-form').onsubmit = () => {
fetch('/emails', {
  method: 'POST',
  body: JSON.stringify({
    recipients: document.querySelector('#compose-recipients').value,
    subject: document.querySelector('#compose-subject').value,
    body: document.querySelector('#compose-body').value
.then(response => response.json())
.then(result => {
return false;

inbox.html (relevant code)

  <div id="compose-view">

       <h3>New Email</h3>
       <form id="compose-form">
            <div class="form-group">
                From: <input disabled class="form-control" value="{{ request.user.email }}">
            <div class="form-group">
                To: <input id="compose-recipients" class="form-control">
            <div class="form-group">
                <input class="form-control" id="compose-subject" placeholder="Subject">
            <textarea class="form-control" id="compose-body" placeholder="Body"></textarea>
            <input type="submit" class="btn btn-primary"/>


{% endblock %}

{% block script %}
    <script src="{% static 'mail/inbox.js' %}"></script>
{% endblock %}
  • Your load_mailbox function runs in an infinite loop. Also, I think that instead of writing a new function, you, by mistake, erased all the code that was previously given for the load_mailbox function in the zipped inbox.js – Vsjain Feb 11 at 6:51

You must log in to answer this question.

Browse other questions tagged .