alias
Новичок
Вот функция для подготовки письма:
Отправка:
Вот результат imap_fetchbody($connect, $v->msgno, 1, FT_PEEK);
Из-за служебной инфы при перекодировке возвращает пустую строку.
При отправке таких писем на gmail - все ок.
Я не могу понять, или у меня проблема в заголовках или я считываю не так?
PHP:
public function compose($form) {
$salt = md5(time());
$pre = '<html><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body>';
$post = '</body></html>';
$this->to = $form['to'];
$this->subject = quoted_printable_encode($form['subject']);
$this->headers = 'From: ' . $this->login . PHP_EOL;
$this->headers .= 'Reply-To: ' . $this->login . PHP_EOL;
$this->headers .= 'To: ' . $this->to . PHP_EOL;
$this->headers .= 'Date: ' . date('r') . PHP_EOL;
$this->headers .= 'Subject: ' . $this->subject . PHP_EOL;
$this->headers .= "MIME-Version: 1.0" . PHP_EOL;
if (isset($form['attachments']) && sizeof($form['attachments'])) {
$this->headers .= "Content-Type: multipart/mixed; boundary=\"mixed-" . $salt . "\"" . PHP_EOL . PHP_EOL;
$this->headers .= "--mixed-" . $salt . PHP_EOL;
}
$this->headers .= "Content-Type: multipart/alternative; boundary=\"alt-" . $salt . "\"" . PHP_EOL;
$this->body = "--alt-" . $salt . PHP_EOL;
$this->body .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
$this->body .= "Content-Type: text/html; charset=utf-8" . PHP_EOL . PHP_EOL;
$this->body .= quoted_printable_encode($pre . $form['body'] . $post) . PHP_EOL . PHP_EOL;
$this->body .= "--alt-" . $salt . '--' . PHP_EOL;
if (isset($form['attachments']) && sizeof($form['attachments'])) {
foreach ($form['attachments'] as $v) {
$attachment = chunk_split(base64_encode(file_get_contents($this->root . '/tmp/' . $v)));
$this->body .= PHP_EOL . "--mixed-" . $salt . PHP_EOL;
$this->body .= "Content-Type: application/octet-stream; name=\"" . $v . "\"" . PHP_EOL;
$this->body .= "Content-Disposition: attachment; filename=\"" . $v . "\"" . PHP_EOL;
$this->body .= "Content-Transfer-Encoding: base64" . PHP_EOL . PHP_EOL;
$this->body .= $attachment . PHP_EOL;
}
$this->body .= "--mixed-" . $salt . "--" . PHP_EOL;
}
return $this;
}
PHP:
public function send() {
$data['errors'] = array();
if (!$this->to) {
$data['errors'][] = 'Empty receiver';
}
if (!$this->body) {
$data['errors'][] = 'Empty body';
}
if (!$this->headers) {
$data['errors'][] = 'Empty headers';
}
if (!sizeof($data['errors'])) {
$connect = imap_open($this->imap_url . 'INBOX', $this->login, $this->password);
$msg = $this->headers . $this->to . $this->subject . $this->body;
imap_append($connect, $this->imap_url . 'INBOX.Sent', $msg);
return imap_mail($this->to, $this->subject, $this->body, $this->headers);
} else {
$msg = $this->headers . $this->to . $this->subject . $this->body;
imap_append($connect, $this->imap_url . 'INBOX.Drafts', $msg);
return $data;
}
}
PHP:
--alt-25ffea7b10fd64171b1208cef1d0430e Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 <html><meta http-equiv=3D"Content-Type" content=3D"text/html charset=3Dutf-= 8"></head><body><p>asddas</p></body></html> --alt-25ffea7b10fd64171b1208cef1d0430e--
При отправке таких писем на gmail - все ок.
Я не могу понять, или у меня проблема в заголовках или я считываю не так?
Последнее редактирование: