phpphpmailersendinblue

How Use Sendinblue with PHPMailer


I'm setting up an email configuration with PHPMailer and just work fine with local email in my office, but since I want use Sendinblue as an email API I just stucked and it didn't work.

I tried to find some suggest to fixed it but stucked. Did anyone try to figure out what I'm looking for about Sendinblue with PHPMailer?

With PHPMailer Library in background, I usually use this code to run my program

function send_mail2($from,$from_name,$to,$to_name,$cc,$cc_name,$cc2,$cc_name2,$cc3,$cc_name3,$subjek,$template,$is_smtp,$usermail,$password){
    $sendmail = new PHPMailer();
    if($is_smtp = 'Y'){
        $sendmail->IsSMTP(); // enable SMTP
        // $sendmail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
        $sendmail->SMTPAuth = true; // authentication enabled
        $sendmail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
        $sendmail->Host = "192.x.x.x";
        $sendmail->Port = 465; // or 587
        $sendmail->Username = "xxx@xxx.com";
        $sendmail->Password = "xxx";
    }
    $sendmail->setFrom("xxx@xxx.com","xxx@xxx.com"); //email pengirim
    $sendmail->addReplyTo("xxx@xxx.com","xxx@xxx.com"); //email replay
    $sendmail->addAddress($to,$to_name); 
    $sendmail->AddCC($cc,$cc_name); 
    $sendmail->AddCC($cc2,$cc_name2); 
    $sendmail->AddCC($cc3,$cc_name3); 
    $sendmail->Subject = $subjek; 
    $sendmail->Body=$template; 
    $sendmail->isHTML(true);
    if(!$sendmail->Send()) {
        return "failed";                  
    }else{ 
      return "success";
    }
}

I just want to find how to use Sendinblue with PHPMailer.


Solution

  • First of all, it looks like you're using an old version of PHPMailer and have based your code on a very old example, so upgrade.

    It doesn't look like you're even trying to use sendinblue; you're pointing your script at a local mail server. Because you're using a literal IP address, SSL will never work because it will fail to verify the certificate.

    If you want to use sendinblue directly from PHPMailer, you need to use sendinblue's SMTP servers, and that will be covered in their documentation. If they don't provide an SMTP service (like say mailgun does), you will need to use their HTTP API instead (which has plenty of documentation). You can't use PHPMailer for talking to that, though you can use it for generating messages to send, for example by doing everything as you currently are except don't call send(); do this instead:

    $message = $sendmail->getSentMIMEMEssage();
    

    This will give you a fully-formatted RFC822 message ready to submit to an HTTP API.