0

I'm using file_get_contents() to get my webpage and email it to users

I'm using it in this way:

$html=file_get_contents($path);

and it brings the webpage along with the images but when I use it to send an email it doesn't send images with it.

My code is shown below. I have defined $path in the beginning and it works perefectly.

$html =file_get_contents($path);
$file = $path; 
$crlf = "\r\n"; 
$hdrs = array( 
          "From"    => "members@********.com", 
          "Subject" => "Nice to meet you" 
          ); 

$mime = new Mail_mime($crlf); 

$mime->setTXTBody($text); 
$mime->addHTMLImage ($file, "images/jpeg"); 
$mime->setHTMLBody($html); 

$body = $mime->get(); 
$hdrs = $mime->headers($hdrs); 


$mail =& Mail::factory("mail"); 
$mail->send($contact_email, $hdrs, $body); 

I receive an email with the text and css but the images are not getting loaded

Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65
Edi 0
  • 212
  • 5
  • 22
  • 1
    Are you using absolute paths to the images on the server in your html/css? The images won't be downloaded to the "email" with file_get_contents. – Louis Huppenbauer Sep 11 '12 at 14:20
  • It's not because your email client is blocking the display of images, is it? – andrewsi Sep 11 '12 at 14:22
  • when i press display images on gmail it fails to load them – Edi 0 Sep 11 '12 at 14:24
  • I notice you're using a `Mail` class. You haven't specified which class you're using, so it's hard to give specific instruction on how to use it. However I would strongly recommend PHPMailier as an excellent solution. Very easy to use, especially with attachments. See also my answer here: http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail/12302354#12302354 – SDC Sep 11 '12 at 14:27
  • He's obviously using Pear. @user1457334 Right click the images that are not loaded and open in new tab or view the mail raw contents in your browser and find out the real location, then you'll know how to correct your code. – Chibueze Opata Sep 11 '12 at 14:31

1 Answers1

0

I assume your img link has relative path like

img src='image/image.png' if so then change it to

img src='http://yoursite/image_location/image.png'

or may be your email client is blocking image

Surace
  • 701
  • 3
  • 8
  • i mean to say .. in Html part of email can i use iframe and give the source of webpage that i want to email to user. – Edi 0 Sep 11 '12 at 14:56
  • Instead of this $html =file_get_contents($path); I will use $html="" – Edi 0 Sep 11 '12 at 14:57