1
Я пытаюсь создать почтовый индекс изображений, а затем отправлю электронное письмо и приложите файл .zip к пользователю. Однако письмо не отправляется. Я использую mail() в другом месте на сервере, поэтому я знаю, что сервер не блокирует эту функцию.PHP Mail() Не удалось отправить электронное письмо с приложением
if((mysqli_num_rows($gallery_query) >= 1) || ($_SESSION['permission'] == 1)){
$photos = array();
while($photo = mysqli_fetch_assoc($gallery_query)){
$file_headers = @get_headers($photo[path]);
if($file_headers[0] == 'HTTP/1.1 404 Not Found' || $file_headers[0] == 'HTTP/1.1 403 Not Found' || $file_headers[0] == 'HTTP/1.0 404 Not Found' || $file_headers[0] == 'HTTP/1.0 403 Forbidden') {
$file_headers = @get_headers($photo[image]);
if($file_headers[0] == 'HTTP/1.1 404 Not Found' || $file_headers[0] == 'HTTP/1.1 403 Not Found' || $file_headers[0] == 'HTTP/1.0 404 Not Found' || $file_headers[0] == 'HTTP/1.0 403 Forbidden') {
//If we made it here we dont' have a copy of the image
} else {
$photos[] = $photo[image];
}
} else {
$photos[] = $photo[path];
}
}
//Begin zipping
$zip = new ZipArchive();
$tmp_file = tempnam('.','');
$zip->open($tmp_file, ZipArchive::CREATE | ZIPARCHIVE::OVERWRITE);
foreach($photos as $file){
try{
// download file
$download_file = file_get_contents($file);
//add it to the zip
$zip->addFromString(basename($file),$download_file);
} catch(Exception $e){
}
}
$zip->close();
} //End if mysqli_num_rows >= 1
$htmlbody = " Your Mail Contant Here.... You can use html tags here...";
$to = $email; //Recipient Email Address
$subject = "Images"; //Email Subject
$random_hash = md5(date('r', time()));
$headers = "From: [email protected]\r\nReply-To: [email protected]";
$headers .= "MIME-Version: 1.0\n\r";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($tmp_file)));
//define the body of the message.
$message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";
//Insert the html message.
$message .= $htmlbody;
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
//include attachment
$message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip; name=\"images.zip\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n";
$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";
//send the email
$mail = mail($to, $subject , $message, $headers);
echo $mail ? "Mail sent" : "Mail failed";
'/ r/n', который должен читать как' \ r \ n' - Тогда '$ headers. =" MIME-Version: 1.0 \ n \ r ";' to '$ headers. =" MIME -Version: 1.0 \ r \ n ";' - последнее может быть не так важно, но вы можете попробовать. –
Я также заметил, что вы используете сеансы. Убедитесь, что сеанс запущен, если вы этого еще не сделали, а не выводить перед заголовком. Добавьте отчет об ошибках в начало вашего файла (ов) сразу после вашего первого открытия ' Php' tag ' Php error_reporting (E_ALL); ini_set ('display_errors', 1); ?> 'Посмотрите, если это что-то уступит. –
хаха это было так просто (/ r/n to \ r \ n) ... Спасибо! Я приму свой ответ, как только переполнение стека позволит мне. – user1890328