Answer the question
In order to leave comments, you need to log in
Why can't the attached picture, via PHP to the letter, be opened?
The problem is the following, the picture is attached, but downloading it does not open anything. What could be the problem?
<?php
$uploaddir = '../img/upload/home-bg.jpg';
$to = '[email protected]';
$subject = "Some";
$message ='
<html>
<head>
<title>' . $subject . '</title>
</head>
<body>
<p>Картинка:</p>
</body>
</html>';
$fp = fopen($uploaddir,"r");
$file = fread($fp, filesize($uploaddir));
fclose($fp);
$boundary = md5(time());
$eol = "\r\n";
echo filesize($uploaddir);
echo basename($uploaddir);
echo mime_content_type($uploaddir);
echo pathinfo($uploaddir, PATHINFO_EXTENSION);
$headers = "MIME-Version: 1.0" . $eol;
$headers .= "From: Test" . $eol;
$headers .= "Reply-To: $user_email" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary= $boundary " . $eol;
$body = "--$boundary" . $eol;
$body .= "Content-Type: text/html; charset=utf-8" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= chunk_split(base64_encode($message));
$body .= "--$boundary" . $eol;
$body .= "Content-Type: mime_content_type($uploaddir); name=" . basename($uploaddir) ."" . $eol;
$body .= "Content-Disposition: attachment; filename=" . basename($uploaddir) ."" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .="X-Attachment-Id: ".rand(1000,99999)."" . $eol;
$body .= chunk_split(base64_encode($file));
mail($to,$subject,$body,$headers);
Answer the question
In order to leave comments, you need to log in
At a minimum, the closing boundary
$body .= "--$boundary" is missing. $eol."--";
at the end.
And most likely there is still not enough empty line between the headings and the body of each desk.
If it does not help, put somewhere what comes.
try with these edits:
<?php
$uploaddir = '../img/upload/home-bg.jpg';
$to = '[email protected]';
$subject = "Some";
$message ='
<html>
<head>
<title>' . $subject . '</title>
</head>
<body>
<p>Картинка:</p>
</body>
</html>';
$fp = fopen($uploaddir,"rb");
$file = fread($fp, filesize($uploaddir));
fclose($fp);
$boundary = md5(time());
$eol = "\r\n";
echo filesize($uploaddir);
echo basename($uploaddir);
echo mime_content_type($uploaddir);
echo pathinfo($uploaddir, PATHINFO_EXTENSION);
$headers = "MIME-Version: 1.0" . $eol;
$headers .= "From: Test" . $eol;
$headers .= "Reply-To: $user_email" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=".$boundary. $eol;
$body = $eol."--$boundary" . $eol;
$body .= "Content-Type: text/html; charset=utf-8" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= $eol;
$body .= chunk_split(base64_encode($message));
$body .= $eol;
$body .= "--$boundary" . $eol;
$body .= "Content-Type: ".mime_content_type($uploaddir)."; name=" . basename($uploaddir) ."" . $eol;
$body .= "Content-Disposition: attachment; filename=" . basename($uploaddir) ."" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .="X-Attachment-Id: ".rand(1000,99999)."" . $eol;
$body .= $eol;
$body .= chunk_split(base64_encode($file));
$body .= $eol;
$body .= "--$boundary"."--".$eol;
mail($to,$subject,$body,$headers);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question