'Why would a function keyword not be recognized inside a <script type="text/javascript"> tag?

I am creating an emailing function on a website. The concept is that a button will automatically send an attachment to a pre-programmed email address, but the script cannot recognize the "function" keyword as such and treats it as plain text. I am doing it with SMTPJS and this is the code:

<Divider type="vertical" />

<input type="button" value={"Send Email"} onClick="sendEmail()"></input>
<script src="https://smtpjs.com/v3/smtp.js" type="text/javascript">
  function sendEmail() {
    Email.send({
      host: "smtp.gmail.com",
      Username: "[email protected]",
      Password: "password",
      To: '[email protected]',
      From: "[email protected]",
      Subject: "This is the subject",
      Body: "And this is the body",
      Attachments: [{
        name: "smtpjs.png",
        path: "https://networkprogramming.files.wordpress.com/2017/11/smtpjs.png"
      }]
    }).then(
      message => alert(message)
    )
  };
</script>

The precedent I am finding for SMPTJS use a classic HTML document layout with a head and body, but I need this to be just another element - i.e. a button with a script on the webpage in the context of a larger ReactJS file and I am not getting why the function doesn't register, even with the type defined in the source. I haven't been able to find this particular issue in SO or the wider interwebs, neither, and it doesn't appear to be a spelling issue, but it might be a syntax one. For more context:

enter image description here\

Error that comes up:

enter image description here

Any insight will be appreciated.

UPDATE:

Correcting the tag syntax still does not make the function appear as such:

enter image description here

What will make the function appear is removing the close of the tag, which makes the entire section invalid:

enter image description here

Can this be an issue with JS itself, or some problem with the particular release version?!

UPDATE:

If I add the stmp.js file to the project and import it:

enter image description here

the following errors appear about the library file:

enter image description here

It feels like a catch-22.



Solution 1:[1]

You can't have both an src in a <script> tag and code. It's either one or the other.

Also, the type is not needed.

<script src="https://smtpjs.com/v3/smtp.js"></script>
<script>
    function sendEmail() {}
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gen_Eric