I'm using the PHP Swift Mailer library (http://swiftmailer.org/) to send email to users. Following their documentation about sending embedded images (http://swiftmailer.org/docs/embedding-dynamic-content/) I have the following code the send images. The problem is that the images aren't sending so I'm guessing that I haven't actually created them or stored them in a way that is usable. I'd like to be able to send them without saving them to disk which, I believe, should be possible.
function resetpassword($username, $password) {
global $loginDatabase;
$font = 4;
$width = ImageFontWidth($font) * strlen($password);
$height = ImageFontHeight($font);
$im = @imagecreatetruecolor ($width,$height);
imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0, 0, 0);
imagestring ($im, $font, 0, 0, $password, $text_color);
$subject = "Password Reset";
$userInfo = $loginDatabase->getUserInfo($username);
$mailer = Swift_Mailer::newInstance ( $this->transport );
$message = Swift_Message::newInstance($subject);
$message->setContentType('text/html');
$message->setFrom ( array (SERVICE_ADDR => SITE_NAME ) );
$message->setTo ( array ($userInfo['email'] =>$userInfo['firstname']." ".$userInfo['lastname'] ) );
$message->setBody ( '<html>' .
' <head></head>' .
' <body>' .
$userInfo['firstname'] .', your password has been reset as you requested.<br />'.
'Your new password is:<br />'.
'<img src="' .
$message->embed(Swift_Image::newInstance($im, 'image.jpg', 'image/jpeg')).
'" alt="Image" /><br />' .
' Please login and change this as soon as possible.<br />'.
' Thank you.'.
' </body>' .
'</html>',
'text/html' //Mark the content-type as HTML
);
return $mailer->send ( $message );
}