I'm currently busy with phpmailer and am wondering how to automatically insert local images into my email address using a script. My idea was to upload an html file and an image folder and let the script replace <imgsrc tags with cid tags.
Now, what I got so far:
$mail = new PHPMailer(true);
$mail->IsSendmail();
$mail->IsHTML(true);
try
{
$mail->SetFrom($from);
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = embed_images($message, $mail);
$mail->Send();
}
Now I have this incomplete function that scans the html body and replaces the src tags:
function embed_images(&$body, $mailer)
{
preg_match_all('/<img.*?>/', $body, $matches);
if (!isset($matches[0])) return;
$i = 1;
foreach ($matches[0] as $img)
{
$id = 'img'.($i++);
}
$mailer->AddEmbeddedImage('i guess something with the src here');
$body = str_replace($img, '<img alt="" src="cid:'.$id.'" style="border: none;" />', $body);
}
I'm not sure what I should do here, do you extract src and replace it with cid: $ id? Since they are local images, I have no problem with src web links or any other ...