Sendmail fills my logs with errors

sendmail({
    from: 'no-reply@yourdomain.com',
    to: 'myemail@gmail.com',
    subject: 'LankyBox01 - New Message from Visitor',
    html: document.getElementById("Test").value,
  }, function(err, reply) {
    console.log(err && err.stack);
    console.dir(reply);
});

I want to make it so that the “html” is the value of an <input>. Instead, this is what i get:
ReferenceError: document is not defined

I’m going to assume this is on the server side, if so, you can’t directly call the values of elements server side.

1 Like

So, what can i do to fix this?

So let me break this down
You cannot use document or manipulate the DOM in Node.js. The sendmail npm package only works in Node.js and cannot be used in the browser.

Also, using JavaScript in emails is a really bad practice and can even get your email rejected and ruin your spam score (the higher the score, the more likely it will go to spam or be rejected)

If you want to get the value of a form and submit it, you could use Ajax (like @RiversideRocks’s answer says) or use HTML forms as it’s a bit easier to validate if you are sending to an actual email or to INSERT INTO email_table (email) VALUES ("<script>alert('xss')</script>") (a sample XSS payload/troll answer. Also using html forms allows users without javascript enabled to use your site.

1 Like

You will need to use Javascript to send the contents of the textbox to the server.

Check out this (it uses jquerey)

1 Like

Thanks, i’ll see if it works.

2 Likes

Be sure to include jQuery on your site.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

1 Like

Ok, i’ll make sure to include this on my site.

2 Likes