I am using the sendgrid-php
lib to send e-mails trough Sendgrid, now I want to use some images, but GMail refuses to open them, as they are on server side. To overcome this behavior I want to attach the images to the e-mail, and display them on the e-mail's body.
Here is my current code:
require("./sendgrid-php/sendgrid-php.php");
$html = '
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,300" rel="stylesheet" type="text/css">
</head>
<body style="background-color: #7bb241; padding: 10px 0;">
<img alt="Projekt Fitness" height="56" src="http://domain/title.png" width="350" style="margin: 40px auto 0 auto; display: block;"/>
<div style=\'width: 600px; margin: 40px auto; background-color: white; border-radius: 3px; padding: 20px; font-family: "Source Sans Pro", Helvetica, sans-serif; font-weight: 300; font-size: 18px;\'>
<p>Hello <b>Jonh Doe</b>,</p>
<p style="text-align: justify;">
Thanks for subscribing! Soon you will receive our first newsletter!
</p>
</div>
</body>
</html>
';
$sendgrid = new SendGrid('myuser', 'mypwd');
$email = new SendGrid\Email();
$email
->addTo('[email protected]')
->setFrom('contato@domain')
->setFromName("Cool Newsletter")
->setSubject('Welcome to our newsletter')
->setHtml($html)
;
$sendgrid->send($email);
You can accomplish this using inline CID on the image tag.
Please let me know if you have further questions!