0

For some reason I'm just getting emails to apple emails but gmail, Microsoft etc. I'm using my own smtp server with SSL, I checked SPF and there is no problems. I also checked headers and etc.

I also try using PHPMailer but only sends with gmail smtp. Any help or direction to fix this issue will be very appreciated!

function send_mail($to, $subject, $message) {
    $CI = get_instance();
    
    $email_library = get_email_library();

    if($email_library == 'codeigniter'){
        $email_config = Array();
        $email_config["protocol"] = "smtp";
        $email_config["charset"] = "utf-8";
        $email_config["mailtype"] = "html";
        $email_config["smtp_host"] = smtp_host();
        $email_config["smtp_port"] = smtp_port();
        $email_config["smtp_user"] = smtp_email();
        $email_config["smtp_pass"] = smtp_password();
        $email_config["smtp_crypto"] = smtp_encryption();
        if($email_config["smtp_crypto"] == 'none'){
            $email_config["smtp_crypto"] = "";
        }
        $CI->load->library('email', $email_config);
        $CI->email->clear(true);
        $CI->email->set_newline("\r\n");
        $CI->email->set_crlf("\r\n");
        $CI->email->from(from_email(), company_name());
        $CI->email->to($to);
        $CI->email->subject($subject);
        $CI->email->message($message);
        if($CI->email->send()){
            return true;
        }else{
            return false;
        }
    }else{
        require_once('vendor/phpmailer/class.phpmailer.php');
        $CI = new PHPMailer(); 
        $CI->IsSMTP(); 
        $CI->SMTPDebug = 1; 
        $CI->SMTPAuth = true;
        $CI->SMTPSecure = smtp_encryption();
        $CI->Host = smtp_host();
        $CI->Port = smtp_port();
        $CI->IsHTML(true);
        $CI->Username = smtp_email();
        $CI->Password = smtp_password();
        $CI->SetFrom(from_email());
        $CI->Subject = $subject;
        $CI->Body = $message;
        $CI->AddAddress($to);
        if($CI->Send()){
            return true;
        }else{
            return false;
        }
    }
}
Vickel
  • 7,879
  • 6
  • 35
  • 56
Sabino Diaz
  • 123
  • 1
  • 5
  • If mail is working to some addresses but not others, then there is nothing wrong with your code, the problem is almost certainly that your msgs are being flagged as spam. If you're using "*my own smtp server*" this is even more likely, as small/private mail servers have no sender reputation and tend to be blacklisted. https://stackoverflow.com/questions/371/how-do-you-make-sure-email-you-send-programmatically-is-not-automatically-marked, https://stackoverflow.com/questions/5935087/how-do-i-prevent-mails-sent-through-php-mail-from-going-to-spam, https://stackoverflow.com/q/18229279/6089612 – Don't Panic May 06 '22 at 06:18
  • Does this answer your question? [How do you make sure email you send programmatically is not automatically marked as spam?](https://stackoverflow.com/questions/371/how-do-you-make-sure-email-you-send-programmatically-is-not-automatically-marked) – Don't Panic May 06 '22 at 06:19
  • I can see you're using a very old and unsupported version of PHPMailer, which won't help. You don't provide any debug information about why or how it's failing, so we have nothing to go on. It might help if you set `SMTPDebug = 2` and posted the output in your question. – Synchro May 06 '22 at 09:28

0 Answers0