вот код
<?php $boundary = md5(uniqid(time())); $mail = "mail"; if(empty($_POST["subject"]) || empty($_POST["user_mail"])) { http_response_code(400); } $subject = htmlspecialchars($_POST["subject"]); $backMail = htmlspecialchars($_POST["user_mail"]); $html = "<html><head></head> <body>" ; $html .= "Email пользователь:<a href='mailto:{$backMail}'> {$backMail}</a>"; if($_POST["message-text"]) { $messageText = htmlspecialchars($_POST["message-text"]); $html .= "<p>Сообщение пользоавателя: </p>" .$messageText; } $html .= "</body></html>"; $header = "FROM: 'Online book feeback' <{$mail}> \n"; $header .= "TO: {$mail} \n"; $header .= "Subject: {$subject} \n"; $header .= "Mime-Version: 1.0 \n"; $header .= "Content-Type: multipart/mixed; boundary='{$boundary}'"; $body = "\n--{$boundary}"; $body .= "Content-Type: text/plain; charset='windows-1251' \n"; $body .= "Content-Transfer-Encoding: quoted-printable \n"; $body .= $html; if(count($_FILES) > 0) { foreach ($_FILES as $name => $file) { if(!$file["size"]) continue; $file = fopen($file["tmp_name"], "rb"); $body .= "\n--{$boundary}"; $body .= "Content-Type: application/octet-stream;"; $body .= "name=".basename($name)."\n"; $body .= "Content-Transfer-Encoding:base64 \n"; $body .= "Content-Disposition:attachmentn \n"; $body .= base64_encode(fread($file, filesize($file["tmp_name"]))); // вот тут ошибка, пока не понял почему //Warning: fread(): Length parameter must be greater than 0 in E:\OpenServer\domains\localhost\test\sendMail.php on line 48 } } $body .= "{$boundary}--"; if(mail($mail, $subject, $body, $header)){ echo "Письмо успешно отправлено"; } else { http_response_code(400); } ?> |
Цитата:
![]() Цитата:
|
Цитата:
|
всеравно не работает, почему на почту приходит пустое письмо??
что я не так сделал? <?php $boundary = md5(uniqid(time())); $mail = "mail"; if(empty($_POST["subject"]) || empty($_POST["user_mail"])) { http_response_code(400); } $subject = htmlspecialchars($_POST["subject"]); $backMail = htmlspecialchars($_POST["user_mail"]); $html = "<html><head></head> <body>" ; $html .= "Email пользователь:<a href='mailto:{$backMail}'> {$backMail}</a>"; if($_POST["message-text"]) { $messageText = htmlspecialchars($_POST["message-text"]); $html .= "<p>Сообщение пользоавателя: </p>" .$messageText; } $html .= "</body></html>"; $header = "FROM: 'Online book feeback' <{$mail}> \n"; $header .= "TO: {$mail} \n"; $header .= "Subject: {$subject} \n"; $header .= "Mime-Version: 1.0 \n"; $header .= "Content-Type: multipart/mixed; boundary='{$boundary}' \n"; $body = "--{$boundary} \n"; $body .= "Content-Type: text/html; charset='utf-8' \n"; $body .= "Content-Transfer-Encoding: quoted-printable \n"; $body .= $html; if(count($_FILES) > 0) { foreach ($_FILES as $name => $file) { if(!$file["size"]) continue; $fopn = fopen($file["tmp_name"], "rb"); $body .= "--{$boundary}\n"; $body .= "Content-Type: application/octet-stream; \n"; $body .= "name=".basename($name)."\n"; $body .= "Content-Transfer-Encoding:base64 \n"; $body .= "Content-Disposition:attachment \n"; $body .= base64_encode(fread($fopn, filesize($file["tmp_name"]))); } } $body .= "{$boundary}--"; if(mail($mail, $subject, $body, $header)){ echo "Письмо успешно отправлено"; } else { http_response_code(400); } ?> |
хз, подключи либу какую-нибудь для mail'инга, чтоб не возиться с этим "низкоуровневым" барахлом.
|
Цитата:
|
Цитата:
Помню что тоже нужна была. Так я загуглил, взял первую попавшуюся и был доволен как слон :) К слову файлы тоже аттачил. |
Короче, глянул - PHPMailer юзал я.
Цитата:
|
Цитата:
|
Не атачь мозг. Юзай и качай исходники . И надо если дорабатывй
|
Часовой пояс GMT +3, время: 19:56. |