How to send image in PHP mail function

后端 未结 2 1803
盖世英雄少女心
盖世英雄少女心 2020-12-10 09:57

I want to send image in mail.How to add image so that it will show in the email I want to add image to the CLIENT MESSAGE BODY. How to use html in client message body?

相关标签:
2条回答
  • 2020-12-10 10:44
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    $message = "<html><head>
    <title>Your email at the time</title>
    </head>
    <body>
    <img src=\"http://www.myserver.com/images_folder/my_image.jpg\">
    </body>"
    mail($email_to, $email_subject , $message,$headers);
    
    0 讨论(0)
  • 2020-12-10 10:49

    You cannot display images on text/plain emails as shown above. You must send it as text/html.

    So you first have to extend your headers like this:

    $header = "From: $noreply@intaxfin.com\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
    

    Then you must update your mailcontent replacing \n or linebreaks with html tags <br> or even <p>

    Then you also can include image tags having the image you want to show in the email

    <img src="http://www.yourserver.com/myimages/image1.jpg">
    

    This will be downloaded from your webserver when recipient opens it.

    .

    BUT the much better way will be to use phpMailer Class

    Using this, you will be able to include any images IN your email, without need to download it from any website. It is easy to learn and absolutely customizable.

    By the way: You should use quotation marks for your $body and $body2 values...

    $body= "<<<EOD
    Contact Form Details of $nameFeild
    
    Name: $nameFeild \n
    City: $cityFeild \n
    Country: $countryFeild \n"
    
    0 讨论(0)
提交回复
热议问题