title: Sending Base64 Images using Laravel
body: <p>I am using Laravel to send emails and plain text works fine. However, I am having an issue attaching images to the email. As of right now, images are stored in the DB as Base64 Strings. </p>
  
  <p>This is the code that calls the Mail facade in Laravel:</p>
  
  <pre><code>            Mail::queue('emails.infraction', $data, function($message) use ($email){
              $message -&gt; from($fromEmail, 'Blah);
              $message -&gt; to($toEmail) -&gt; subject('Testing');
  
          });
  </code></pre>
  
  <p>Basically the $data variable contains all the information I will be displaying in the HTML email that is being sent. I can access the variables just fine when displaying them in the email but I am having issues attaching the base64 images into the email.</p>
  
  <p>This is what I have tried so far:</p>
  
  <pre><code>        Evidence of Intraction:&lt;/p&gt;
              &lt;?php 
                  $elementCount  = count($photos);
                  for($x=0; $x&lt;$elementCount; $x++){
                      echo '&lt;p style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; margin-left: 80px;"&gt;';
                      echo "&lt;img src=" . $message-&gt;embedData($data['photos'][$x], 'Blah') . "&gt;";
                      echo "&lt;/p&gt;";
                  }
              ?&gt;
  </code></pre>
  
  <p>But as you can see here, gmail does not properly encode that rawDataString into the image:</p>
  
  <p><a href="https://i.stack.imgur.com/aJZ1m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aJZ1m.png" alt="laravel"></a></p>
  
  <p>It just displays as if a picture was there but not the contents. I have verified the base 64 string and it is correct. </p>
  
  <p>What could be the error? </p>
  
  <p>Laravel Mail Documentation says to use something like this in the message builder:</p>
  
  <p><a href="https://i.stack.imgur.com/ZwrUn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZwrUn.png" alt="laravel mailer"></a></p>
  
  <p>but I am a little lost on how to do that properly. The other option would be to convert the base64 string into an image on the fly and send it as an attachment to the user but I cannot store the images into the server and thus would have to convert it to an image within php and sending it through laravel mailer without an actual filepath.</p>
  
  <p>Please advise</p>