Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add image to php mail body

Tags:

php

I'm trying to add image to mail body from folder.but it not display only display text on alt tag.this is my code.

<?php 
   $to = $email;
        $subject="Reservation notification From abc";
        $from = '[email protected]';
            $body = '<html><body>';
            $body .= '<img src="img/logo.png" alt="Hotel" /><br/>';
            $body .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
            $body .= '<p style="color:#3366FF;font-size:14px;">Hello'.' '.$name.',</p>';
            $body .= "</table>";
            $body .= "</body></html>";

        $headers = "From: $from \r\n";
        $headers .= "Reply-To: $$from \r\n";
        $headers = 'MIME-Version: 1.0' . "\r\n" .
           'Content-type: text/html; charset=iso-8859-1' . "\r\n" .

           'X-Mailer: PHP/' . phpversion();

        mail($to, $subject, $body,$headers);
?>
like image 562
KT1 Avatar asked Dec 04 '25 17:12

KT1


1 Answers

This should work as expected:

<?php 
    ...
    $body .= '<img src="http://domain.com/absolute/path/to/image/img/logo.png" alt="Hotel" /><br/>';
    ...
?>
like image 165
Ananth Avatar answered Dec 06 '25 07:12

Ananth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!