Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
How do I get the same formating in my email as on my website?

I've made a website where you fill out a form and then it saves the form data into a JSON file. The data is shown on the site like this:

After that, I send the data in an email. But the email is formatted like this:

How do I get the email to have the same format as the website does? I suspect that the formatting changes where I save the data to the JSON file and then read it again. But I'm not sure and if it is I don't know how to fix it.

Here is the code:

var fs = require('fs')
var formidable = require("formidable")
var util = require('util')

var mailFunctions = require('./mailFunction.js');

'use strict';

function processAllFieldsOfTheForm(req, res) {
  var form = new formidable.IncomingForm();
  form.parse(req, function (err, fields, files) {
    res.writeHead(200, {
      'content-type': 'text/plain'
    });
    res.write('received the data:\n\n');
    res.end(util.inspect( {
      fields: fields,
      files: files
    }));
  });
}

function processFormFieldsIndividual(req, res) {
  var fields = [];
  var form = new formidable.IncomingForm();
  form.on('field', function (field, value) {
    fields.push([field, value]);
  });
  // Display data to user
  form.on('end', function() {
    var objectToJSON = JSON.stringify({
      fields: fields
    }, null, 2)
    fs.writeFile('C:/Users/admin/Desktop/Node.js/test/source/json/answers.json', objectToJSON, (err) => {
      if (err) {
        console.log(err);
        console.log('Error while writing file')
        throw err;
      }
    })
    res.writeHead(200, {
      'content-type': 'text/plain'
    });
    res.write('received the data: \n\n');
    res.end(util.inspect( {
      fields: fields
    }));
  });
  // Returns data inside file
  form.on('end', function() {
    fs.readFile('C:/Users/admin/Desktop/Node.js/test/source/json/answers.json', (err, data) => {
      if (err) {
        console.log(err)
        console.log('Error while reading file')
        throw err;
      }
      else {
        mailFunctions.makeMail(data)
      }
    });
  });
  form.parse(req);
}

I'm also kinda new to node.js so there is probably so useless/bad code in there.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You didn't include the only relevant part of your source code (the mailFunction.js file) so it's impossible to tell you what's wrong with it. (Also, what's with the screenshots? Are we supposed to use photoshop to fix it? If developers has lost the ability to copy and paste code then there is no hope.)

Now, it's also impossible to tell you how to make an email that looks like your website when we don't know how your website looks like, isn't it, and all that can be said here is a very general advice.

You need to use some templating system to produce HTML (I assume it's HTML but it's also possible that all you need is plain text - again, it's impossible to tell from your question) and you need to make sure that that HTML is correctly formatted for emails - which is quite different than formatting for websites, something that a lot of people don't know.

Then you need to correctly send the HTML email along with all of the attachments because you cannot reliably reference images and other assets hosted on your servers.

There are good modules on npm that can help you with all of those steps. For sending the mail you can use Nodemailer:

  • https://www.npmjs.com/package/nodemailer

To use templating with Nodemailer, see:

  • https://community.nodemailer.com/2-0-0-beta/templating/

To send the email it's best to use a transactional email service like Mandrill, Mailgun or Amazon SES if you don't want getting blocked by your ISP and your mail going to spam folders of your users. See:

  • http://www.mandrill.com/
  • https://www.mailgun.com/
  • https://aws.amazon.com/ses/

All of those are supported by Nodemailer.

To know how to format the actual HTML and CSS for your emails to look like you want, see those tutorials:

  • https://templates.mailchimp.com/getting-started/html-email-basics/
  • http://blog.mailgun.com/building-html-email-and-workflow-tips/
  • http://blog.mailgun.com/transactional-html-email-templates/
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!