def METHOD_NAME(userid, form):
    form.title = form.title.strip()
    form.content = form.content.strip()
    if not form.content:
        raise WeasylError("contentInvalid")
    elif not form.title:
        raise WeasylError("titleInvalid")
    elif len(form.title) > 100:
        raise WeasylError("titleTooLong")
    users = set(d.get_userid_list(form.recipient))
    # can't send a note to yourself
    users.discard(userid)
    # can't send a note to a user who ignores you
    users.difference_update(
        d.column(d.engine.execute("SELECT userid FROM ignoreuser WHERE otherid = %(user)s", user=userid)))
    # can't send a note to an unverified user
    users.difference_update(
        d.column(d.engine.execute("SELECT userid FROM login WHERE userid = ANY (%(users)s) AND voucher IS NULL", users=list(users))))
    # can't send a note to a user you're ignoring
    users.difference_update(ignoreuser.cached_list_ignoring(userid))
    if not users:
        raise WeasylError("recipientInvalid")
    configs = d.engine.execute(
        "SELECT userid, config FROM profile WHERE userid = ANY (%(recipients)s)",
        recipients=list(users)).fetchall()
    if userid not in staff.MODS:
        ignore_global_restrictions = {i for (i,) in d.engine.execute(
            "SELECT userid FROM permitted_senders WHERE sender = %(user)s",
            user=userid)}
        remove = (
            # Staff notes only
            {j[0] for j in configs if "y" in j[1]} |
            # Friend notes only
            {j[0] for j in configs if "z" in j[1] and not frienduser.check(userid, j[0])}
        )
        users.difference_update(remove - ignore_global_restrictions)
    if not users:
        raise WeasylError("recipientInvalid")
    elif len(users) > 10:
        raise WeasylError("recipientExcessive")
    d.engine.execute(
        "INSERT INTO message (userid, otherid, title, content, unixtime)"
        " SELECT %(sender)s, recipient, %(title)s, %(content)s, %(now)s"
        " FROM UNNEST (%(recipients)s) AS recipient",
        sender=userid,
        title=form.title,
        content=form.content,
        now=d.get_time(),
        recipients=list(users),
    )
    for u in users:
        d._page_header_info.invalidate(u)
    d.engine.execute(
        """
        INSERT INTO permitted_senders (userid, sender)
            SELECT %(user)s, sender FROM UNNEST (%(recipients)s) AS sender
            ON CONFLICT (userid, sender) DO NOTHING
        """,
        user=userid,
        recipients=list(users),
    )
    if form.mod_copy and userid in staff.MODS:
        mod_content = (
            '## The following message was sent as a note to the user.\n\n### %s\n\n%s' % (
                form.title, form.content))
        if form.staff_note:
            mod_content = '%s\n\n%s' % (form.staff_note, mod_content)
        now = arrow.utcnow()
        mod_copies = []
        for target in users:
            mod_copies.append({
                'userid': userid,
                'target_user': target,
                'unixtime': now,
                'settings': 's',
                'content': mod_content,
            })
        d.engine.execute(
            d.meta.tables['comments'].insert()
            .values(mod_copies))