ci sto sbattendo la testa da un tot : come si fa secondo voi a inviare una mail PEC con php?
al momenot sto provando con il pacchetto per inviare SSL di PEAR ma mi sono arenato:
- Se giro una mail normale SSL tutto ok.
- Se invio una mail con lo stesso metodo ad una casella pec , da PHP nessun problema, però la mail fisicamente non parte e mi ritorna un messaggio dal server : "e' stato rilevato un problema che ne impedisce l'accettazione
a causa di header non corretto.
Il messaggio non e' stato accettato."
qualcuno ha qualche idea?
il codice è il seguente (ho censurato pass e user per ovvi motivi):
Codice PHP:
require_once "./include/mail/Mail.php";
include('./include/mail/mime.php');
// questi sono gli include PEAR
$from = "tizio caio <tizio.caio@pec.it>";
$to = "Davide Pozzer <popper@email.it>";
$subject = "Hi!";
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = '/home/richard/example.php';
$crlf = "\n";
$hdrs = array(
'Versione-MIME' => '1.0',
'Content-Type' => 'multipart/mixed; ',
'Content-Transfer-Encoding' => '7bit',
'From' => $from,
'Subject' => 'prova mail 2'
);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment("prova.gif", 'image/gif');
//do not ever try to call these lines in reverse order
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$host = "ssl://smtps.pec.aruba.it";
$port = "465";
$username = "tizio.caio@pec.it";
$password = "xxxxxxxxxxx";
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
echo "esito send " . $smtp->send($to, $hdrs, $body) . "
";
if (PEAR::isError($mail)) {
echo("
" . $mail->getMessage() . "</p>");
} else {
echo("
Message successfully sent!</p>");
}