Prova questa classe scaricata da github:
Demo invio:
Codice PHP:
<?php
require_once 'mailer.class.php';
$mail = new Mailer();
$mail->addHeader('X-Priority: High');
$mail->setSubject('Subject');
/* usi questo metodo se devi allegare un file, altrimenti cancelli questa riga*/
$mail->addAttachment('READMY', '...', 'text/plain');
$mail->html('test@gmail.com', '<h1>Тест</h1>')
?>
Codice PHP:
<?php
class Mailer {
protected $charset = 'UTF-8',
$to,
$from,
$subject = '',
$headers = array(),
$attachments = array();
public function setCharset($value) {
$this->charset = $value;
}
public function encode($value) {
return '=?' . $this->charset . '?B?' . base64_encode($value) . '?=';
}
public function setFrom($email, $name = null) {
$this->from = $name ? $this->encode($name) . " <$email>" : $email;
}
public function setSubject($value) {
$this->subject = $this->encode($value);
}
public function addHeader($header) {
$this->headers[] = $header;
}
public function addAttachment($name, $data, $type =
'application/octet-stream') {
$name = $this->encode($name);
$data = chunk_split(base64_encode($data));
$this->attachments[] = compact('name', 'data', 'type');
}
public function send($to, $body, $is_html = 0) {
if ($this->from) {
$this->headers[] = 'From: ' . $this->from;
}
$content_type = 'Content-Type: text/' . ($is_html ? 'html' : 'plain') .
'; charset=' . $this->charset;
$content_transfer_encoding = 'Content-Transfer-Encoding: 8 bit';
if ($count = count($this->attachments)) {
$boundary = uniqid();
$this->headers[] = 'Content-Type: multipart/mixed; boundary="' .
$boundary . '"';
$body = array("--$boundary", $content_type,
"$content_transfer_encoding\r\n", $body);
for ($i = 0; $i < $count; ++$i) {
$body[] = "--$boundary";
$body[] = "Content-Type: " . $this->attachments[$i]['type'] .
"; name=\"" . $this->attachments[$i]['name'] . "\"";
$body[] = 'Content-Disposition: attachment';
$body[] = "Content-Transfer-Encoding: base64\r\n";
$body[] = $this->attachments[$i]['data'];
}
$body = implode("\r\n", $body) . "--$boundary--";
}
else {
$this->headers[] = $content_type;
$this->headers[] = $content_transfer_encoding;
}
return @mail($to, $this->subject, $body, implode("\r\n",
$this->headers));
}
public function html($to, $body) {
return $this->send($to, $body, 1);
}
}
?>
Se vuoi una soluzione valida prova PHP Mailer questo è il link: http://phpmailer.worxware.com/