Problem sending email via PHP. Blind copy is not coming

Question:

I have a PHP file on a site that receives via POST the return sent by PagSeguro about purchases made on the site – customer name , amount paid , e-mail … in short, all the information regarding the purchase.

In this file I have a script that sends a message about the purchase to the customer's email, using the data sent by PagSeguro.

In this script I have a line where I get a blind copy of the message:

$headers .= "Bcc: davidsammuel@gmail.com\r\n";

I always received the message, but I noticed that, for a few days now, I have not received anything, and I even thought that no sales were being made, but sales are taking place normally.

The code is this:

$headers = "MIME-Version: 1.1\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ticiana@ticianawerner.com.br\r\n"; // remetente
$headers .= "Bcc: davidsammuel@gmail.com\r\n";
$headers .= "Return-Path: ticiana@ticianawerner.com.br\r\n"; // return-path
mail($CliEmail, "Cupom Ticiana Werner Restaurante - ".$codCupom, $corpo, $headers);

All variables are correct. I've already done a test by exchanging $CliEmail for my email "davidsammuel@gmail.com" and the message normally arrives in my mailbox, that is, no error happens.

The problem seems to be in the line that sends the blind copy, as I don't get anything:

$headers .= "Bcc: davidsammuel@gmail.com\r\n";

Any idea what it might be? Because I always received this blind copy before and now nothing.

UPDATE:

I changed the "Bcc" to "Cc" and received the copy normally! The problem is the "Bcc" that doesn't work anymore.

Answer:

Gmail is probably thinking it's SPAM, and it won't arrive in the inbox, maybe not even the SPAM inbox (check this first), I recommend you try sending via SMTP.

There is a library called phpmailer , install via composer:

composer require phpmailer/phpmailer

And use it like this:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'vendor/autoload.php';

If you don't have composer, you can download via release and add via url https://github.com/PHPMailer/PHPMailer/releases (the last preference) and add it like this:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

To send do this:

$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = 2; //Ativa o DEBUG, desative quando mandar pro servidor de produção
    $mail->isSMTP();
    $mail->Host = 'smtp.doseuservidor.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'ticiana@ticianawerner.com.br';                 // SMTP username
    $mail->Password = 'SENHA';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Se o seu servidor usar TLS, troque por ssl se necessário, ou remova se não tiver nenhum dos dois
    $mail->Port = 587;                                    // troque pela porta para SSL ou TLS ou sem

    $mail->setFrom('ticiana@ticianawerner.com.br');
    $mail->addAddress($CliEmail);
    $mail->addBCC('davidsammuel@gmail.com');

    $mail->isHTML(true); //Formato HTML
    $mail->Subject = 'Cupom Ticiana Werner Restaurante - '.$codCupom;
    $mail->Body    = $body;
    $mail->AltBody = strip_tags($body);//Alternative em Texto

    $mail->send(); //Envia

    echo 'Email enviado';
} catch (Exception $e) {
    echo 'Erro: ' . $mail->ErrorInfo;
}
Scroll to Top
AllEscort