I'm using PHPMailer to send emails. I'm trying to send an email to an Hotmail account but if the recipient has the sender in contacts, it receives the email. If the recipient doesn't have the sender in contacts, it doesn't receive the email.
Why? What is the matter?
PHPMailer doesn't show any errors.
I have tried a lot of solutions proposed in the network without any result.
This is the code that I use:
public static function invia_email_bis($p_nome_mitt, $p_mitt, $p_dest, $p_ccn, $p_oggetto, $p_header, $p_mess) {
//Se siamo in sviluppo, le email non devono partire. L'ambiente lo rileviamo dal DB
$config =& JFactory::getConfig();
if ($config->getValue( 'config.db' ) == 'fantaonl_dev') {
return;
}
$email_par = email::get_parameter(costanti::actaccount);
//Creazione dell'oggetto PHPMAILER
$messaggio = new PHPmailer();
//Abilitiamo SMTP
$messaggio->IsSMTP();
//Abilitiamo l'autenticazione
$messaggio->SMTPAuth = true;
//Abilitiamo il protocollo SSL
if ( $email_par['PORTA'] == 587 ) {
$messaggio->SMTPSecure = "tls";
}
if ( $email_par['PORTA'] == 465 ) {
$messaggio->SMTPSecure = "ssl";
}
//Server SMTP
$messaggio->Host = $email_par['SMTP'];
$messaggio->Username = $email_par['USERNAME'];
$messaggio->Password = $email_par['PASSWORD'];
//Porta
$messaggio->Port = $email_par['PORTA'];
//Definiamo le intestazioni e il corpo del messaggio
$messaggio->FromName = $p_nome_mitt;
$messaggio->From = $p_mitt;
//$messaggio->SMTPDebug = 1;
//$messaggio->Debugoutput = 'html';
//DESTINATARIO
if ($p_ccn == false) {
for ($t = 0; $t < count($p_dest); $t++) {
if ($p_dest[$t]['EMAIL'] != '') { $messaggio->AddAddress($p_dest[$t]['EMAIL']); }
elseif ($p_dest[$t]['email'] != '') { $messaggio->AddAddress($p_dest[$t]['email']); }
}
}
else {
for ($t = 0; $t < count($p_dest); $t++) {
if ($p_dest[$t]['EMAIL'] != '') { $messaggio->AddBCC($p_dest[$t]['EMAIL']); }
elseif ($p_dest[$t]['email'] != '') { $messaggio->AddBCC($p_dest[$t]['email']); }
}
}
//DESTINATARIO IN CCN
//$mail->AddBCC($p_dest);
//MITTENTE
$messaggio->AddReplyTo($p_mitt, $p_nome_mitt);
//OGGETTO MESSAGGIO
$messaggio->Subject=$p_oggetto;
//Il Messaggio Ë in HTML
$messaggio->IsHTML(true);
$path_html = $_SERVER['DOCUMENT_ROOT'] . '/jumi_includes/class/template_email.html';
$message_body = file_get_contents($path_html);
$message_body = str_replace('%titolo%', $p_header, $message_body);
$message_body = str_replace('%messaggio%', $p_mess, $message_body);
$path_img = $_SERVER['DOCUMENT_ROOT'] . '/templates/sitodefinitivodue/images/header.jpg';
//Path immagine da caricare
$messaggio->AddEmbeddedImage($path_img, 'header', 'header.jpg', 'base64', 'image/jpeg');
//CORPO MESSAGGIO
$messaggio->MsgHTML($message_body);
$messaggio->AltBody = $p_mess;
//Definiamo i comportamenti in caso di invio corretto
//o di errore
if(!$messaggio->Send()){
$esito = 4;
//echo $messaggio->ErrorInfo;
}else{
$esito = 0;
}
//chiudiamo la connessione
$messaggio->SmtpClose();
unset($messaggio);
return $esito;
}