-1

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;
}
rgettman
  • 176,041
  • 30
  • 275
  • 357
user3632160
  • 11
  • 1
  • 3
  • show your code or this question may be closed – noobie-php May 28 '14 at 16:43
  • How do you know the email wasn't sent? Did you mean "hotmail doesn't appear to receive the email" followed by "I've checked spam folder". – Popnoodles May 28 '14 at 16:44
  • 2
    *"phpMailer doesn't send emails to hotmail account"* - Oh, it sends them alright. It's just that Hotmail is one of the worse now to send it to Spam or Trash, rejected altogether. – Funk Forty Niner May 28 '14 at 16:48

2 Answers2

3

It's hotmails spamfilter who kicks in. Nowdays you can't just starting send e-mails and think it will get all the way. To dodge hotmails/gmails spam filter you must:

  • Oblige to USA's CAN-SPAM Act of 2003 witch includes:

    • Never use deceptive headers, from-names, reply-tos, or subject lines.
    • You must always provide an unsubscribe link.
    • Remove recipients from your list within 10 business days.
    • The unsubscribe link must work for at least 30 days after sending.
    • You must include your physical mailing address. To learn more, go to ftc.gov.
  • Send from the correct server, if the SMTP-server you are using dosn't have anything with the domain name you are using it will be blocked. If you send a no-reply@test.com and don't use the correct smtp it will be blocked, and if you continue your smtp server can be blacklisted and if you use an ISP or any other server they will not be happy about it.

  • Not be "spam", spamfilter nowdays analyses the text and tries to figure out if your mail is spam. If you send alot of the same massage with just small text changes your mail will score higher. Like: Hello [Mike], look at our new products etc etc. Avoid using common spam words like e CLICK HERE! or FREE! BUY NOW! etc or bright colors, lots of exclamation, vad html etc.

There is no bulletproff way to avoid a spam filter, if it would your inbox would be filled with spam in no time.

Will Weatons rule apply here (as with SEO): Don't be a dick.

ztripez
  • 664
  • 6
  • 24
0

I think your email has been sent to hotmail user. To send correctly to hotmail, be sure to be correct with DKIM. I doubt it would be DKIM issue. In Hotmail's Safe Sender will auto ignore the email if the sender domain not in the safe list.

Try to check:- Inbox > Options > Safe and blocked senders > Safe senders

Jinn
  • 1
  • 1