Jump to content

E-mailing Image attachment (not working)


Andrius

Recommended Posts

ok on index.php I have this code and yes $image is assigned and working as it should (displays news images on the main page)
[code]<form id='imageform' name='imageform' method='post' action='http://www.nicaprojects.com/image_mailer.php'>
  <BUTTON name='mail_button' type='submit'>Send to friend</BUTTON>
  <input name='to' type='hidden' value='[email protected]' />
  <input name='image' type='hidden' value='/news_images/$image' />
</form>[/code]

then on image_mailer.php I have this code
[code]<?PHP 
$to = $_POST['to'];
$from = '[email protected]';
$image = $_POST['image'];
$subject = 'Image of Nicaragua I thought you may like.';
$bound_text = "jimmyP123";
$bound = "--".$bound_text."\r\n";
$bound_last = "--".$bound_text."--\r\n"; 
   
$headers = "From: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"
  ."Content-Type: multipart/mixed; boundary=\"$bound_text\"";
   
$message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n" 
  .$bound; 
   
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
  ."Content-Transfer-Encoding: 7bit\r\n\r\n"
  ."Hey! Just forwarding you a picture of Nicaragua I thought you may like!\r\n"
  .$bound;
   
$file = file_get_contents("$image"); 
   
$message .= "Content-Type: image/jpg; name=\"nicaragua.jpg\"\r\n" 
  ."Content-Transfer-Encoding: base64\r\n"
  ."Content-disposition: attachment; file=\"nicaragua.jpg\"\r\n"
  ."\r\n"
  .chunk_split(base64_encode($file))
  .$bound_last; 

if(mail($to, $subject, $message, $headers))
{
    echo 'MAIL SENT';
} else {
    echo 'MAIL FAILED';
}

?>[/code]

but when the whole thing runs I get this result:

Warning: file_get_contents(): open_basedir restriction in effect. File(/news_images/LaSaltaDeEstanzuelaWaterfall (Small).jpg) is not within the allowed path(s): (/home/httpd/vhosts/nicaprojects.com/httpdocs:/tmp) in /home/httpd/vhosts/nicaprojects.com/httpdocs/image_mailer.php on line 31

Warning: file_get_contents(/news_images/LaSaltaDeEstanzuelaWaterfall (Small).jpg): failed to open stream: Operation not permitted in /home/httpd/vhosts/nicaprojects.com/httpdocs/image_mailer.php on line 31
MAIL SENT
Link to comment
https://forums.phpfreaks.com/topic/28815-e-mailing-image-attachment-not-working/
Share on other sites

You might have to set the image path to the full server path - /home/httpd/vhosts/nicaprojects.com/httpdocs/news_images/LaSaltaDeEstanzuelaWaterfall (Small).jpg, instead of simply - /news_images/LaSaltaDeEstanzuelaWaterfall (Small).jpg. 

Or, if news_images is easily accessable as a relative path from image_mailer.php, try simply 'news_images/$image', or whatever relative variant, insead of the leading '/', which is trying to take it to the root directory.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.