Send email with PHPMailer - embed image in body

前端 未结 2 597
长发绾君心
长发绾君心 2020-11-28 20:27

I\'m trying to send HTML mail, with PHPMailer, with images. The body is loaded from a html file, that contains all the info.

When sending the mail, the image does no

相关标签:
2条回答
  • 2020-11-28 20:35

    According to PHPMailer Manual, full answer would be :

    $mail->AddEmbeddedImage(filename, cid, name);
    //Example
    $mail->AddEmbeddedImage('my-photo.jpg', 'my-photo', 'my-photo.jpg '); 
    

    Use Case :

    $mail->AddEmbeddedImage("rocks.png", "my-attach", "rocks.png");
    $mail->Body = 'Embedded Image: <img alt="PHPMailer" src="cid:my-attach"> Here is an image!';
    

    If you want to display an image with a remote URL :

    $mail->addStringAttachment(file_get_contents("url"), "filename");
    
    0 讨论(0)
  • 2020-11-28 20:37

    I found the answer:

    $mail->AddEmbeddedImage('img/2u_cs_mini.jpg', 'logo_2u');
    

    and on the <img> tag put src='cid:logo_2u'

    0 讨论(0)
提交回复
热议问题