title: How to send email using sendrid with next js?
body: <p>i have an issue with my contact form. It send email but the user input is undefined.
  When i log the data on the console it is returned correctly but on vs code terminale all the information is undefined.</p>
  <p>console log in browser dev tool return the below</p>
  <pre><code>{firstName: 'test ', email: 'test@test.com', phone: '382552', message: 'test '}
  email: &quot;test@test.com&quot;
  firstName: &quot;test &quot;
  message: &quot;test &quot;
  phone: &quot;382552&quot;
  [[Prototype]]: Object
  </code></pre>
  <p>the console log in vs code terminal</p>
  <pre><code>{
    to: 'info@test.com',
    from: 'info@test.com',
    subject: 'New message from undefined undefined',
    text: '\n' +
      '  FirstName: undefined\r\n' +
      '\n' +
      '  Email: undefined\r\n' +
      '\n' +
      '  phone:undefined\n' +
      '  Message: undefined\r\n' +
      '\n',
    html: '\n' +
      '  FirstName: undefined&lt;br /&gt;\n' +
      '  Email: undefined&lt;br /&gt;\n' +
      '  phone:undefined\n' +
      '  Message: undefined&lt;br /&gt;\n',
  </code></pre>
  <p>The message should be containing the details log on the browser console.</p>
  <p>api/contact</p>
  <pre><code>import cookie from &quot;cookie&quot;;
  
  const mail = require(&quot;@sendgrid/mail&quot;);
  
  mail.setApiKey(process.env.NEXT_PUBLIC_SENDGRID_API_KEY);
  
  // eslint-disable-next-line import/no-anonymous-default-export
  export default async (req, res) =&gt; {
    res.setHeader(
      &quot;Set-Cookie&quot;,
      cookie.serialize(&quot;token&quot;, req.body.token, {
        httpOnly: true,
        secure: process.env.NODE_ENV !== &quot;development&quot;,
        expires: new Date(0),
        maxAge: 60 * 60,
        sameSite: &quot;strict&quot;,
        path: &quot;/&quot;,
      })
    );
  
    const body = JSON.parse(JSON.stringify(req.body));
  
    const message = `
    FirstName: ${body.firstName}\r\n
    Email: ${body.email}\r\n
    phone:${body.phone}
    Message: ${body.message}\r\n
  `;
  
    const data = {
      to: &quot;info@test.com&quot;,
      from: &quot;info@test.com&quot;,
      subject: `New message from ${body.firstName} ${body.phone}`,
      text: message,
      html: message.replace(/\r\n/g, &quot;&lt;br /&gt;&quot;),
    };
    try {
      await mail.send(data);
      console.log(data);
      res.status(200).json({ status: &quot;OK&quot; });
    } catch (error) {
      console.log(&quot;server error&quot;, error);
      if (error.response) {
        console.log(error.response.body);
      }
      res.status(400).json({ status: &quot;ERROR&quot;, message: error.message });
    }
  };
  </code></pre>