-1

Good evening, this is my laravels email blade file, I am trying to convert coordinates to an actual address with geocoding. When I get this delivered to an email (mailtrap.io) I believe that script is ignored, nothing shows up, only an empty DIV. I tried to create just a blank index.html page with this content, just filled out the coordinates manually and script works. And yes, I checked if {{$task->latitude}}, {{$task->longitude}} works, if I write it in a DIV it shows coordinates when I receive email. 1. Mailtraip.io ignores script tags for a security reason? 2. My mistake somewhere?

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <title>Email</title>
</head>
<body>

  <div id="emailOutput">

  </div>

  <script type="text/javascript">
    geocode();
    function geocode(){
      let location = 'lat:{{$task->latitude}}, lng:{{$task->longitude}}';
      axios.get('https://maps.googleapis.com/maps/api/geocode/json',{
        params:{
          address:location,
          key:'AIzaSyBqgKZ40pxXAigIXetiNjSqAGd8xtHLCJQ',
        }
      })
      .then(function (response) {
        let formattedAddress = response.data.results[0].formatted_address;
        let emailOutput =
         `
          <h1>Your <b>work</b> device has been successfully added to database.</h1>
          <p>Device ID: {{$task->deviceId}}</p>
          <p>Address: ${formattedAddress}</p>
        `;

        document.getElementById('emailOutput').innerHTML = emailOutput;
      })
      .catch(function (error) {
        console.log(error);
      });
    }
  </script>

</body>
</html>
  • Not a single mail provider will allow script tag in mail. – anwerj Jun 21 '18 at 15:42
  • Please read [this](https://stackoverflow.com/questions/1088016/html-email-with-javascript) – prateekkathal Jun 21 '18 at 15:42
  • Possible duplicate of [Is JavaScript supported in an email message?](https://stackoverflow.com/questions/3054315/is-javascript-supported-in-an-email-message) – H H Jun 21 '18 at 16:04
  • Possible duplicate of [HTML email with Javascript](https://stackoverflow.com/questions/1088016/html-email-with-javascript) – prateekkathal Jun 21 '18 at 16:38

1 Answers1

0

You aren't going to get executable JavaScript onto a server and into a mail client. But emails DO support links, you can always link to your content within an email.

Azraar Azward
  • 1,586
  • 2
  • 12
  • 16