Problem sending email via PHP. Hidden copy is not coming

Asked

Viewed 361 times

3

I have a PHP file on a website that receives via POST the return sent by Pagseguro on purchases made on the site -- client name, amount paid, e-mail... finally, all the information regarding the purchase.

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

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

$headers .= "Bcc: [email protected]\r\n";

I always got the message, but I noticed that, for a few days now, I haven’t received anything, and I even thought that no sale was being made, but the 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: [email protected]\r\n"; // remetente
$headers .= "Bcc: [email protected]\r\n";
$headers .= "Return-Path: [email protected]\r\n"; // return-path
mail($CliEmail, "Cupom Ticiana Werner Restaurante - ".$codCupom, $corpo, $headers);

All variables are correct. I have already done a test changing the $CliEmail by my email "[email protected]" and the message usually arrives in my mailbox, IE, no mistake happens.

The problem seems to be on the line that sends the hidden copy as I get nothing:

$headers .= "Bcc: [email protected]\r\n";

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

UPDATING:

I changed the "Bcc" to "Cc" and received the copy normally! The problem is the "Bcc" that no longer works.

  • If you stopped sending without the code being changed, the problem must be on the send/receive server. Check for updates/settings performed on the mail server and PHP.

  • @Gabrielheming Yeah, the code hasn’t been moved, it’s still the same. It just stopped sending the hidden copy. Weird that. Only if they changed something on the server and this Bcc no longer works.

1 answer

1


The Gmail probably thinking it’s SPAM, and it won’t get in the Inbox, maybe even the SPAM box will arrive (check this first), 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 by url https://github.com/PHPMailer/PHPMailer/releases (the last of preference) and so add:

<?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 = '[email protected]';                 // 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('[email protected]');
    $mail->addAddress($CliEmail);
    $mail->addBCC('[email protected]');

    $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;
}
  • Thanks for the answer, I’ll try a test. But just in advance, I believe it is not a problem with Gmail, because it has years that it worked well, only a few days to here that the Bcc does not send (but this is until the least, I believe that customers are receiving the message, only I’m not receiving the Bcc). Nor is it a SPAM problem because in addition to the sender email being in my Gmail contacts, it is marked as "trustworthy" by Gmail because all customers receive it normally. No spam shows up either.

  • @DVD but who sent was not the [email protected] actually, it was the server, but I’ve actually been reading a few things about the google products and the Bcc. I’ll wait for your test.

  • Server of Locaweb, I believe that there is no problem with this, even because in one of my tests, "Cc" arrived normal. The problem is the "Bcc" that is not enough.

  • @DVD can be some Google product policy specific to Bcc. As said do the test, because the function mail is not in fact the origin of [email protected] and maybe (emphasis on the word maybe) Google check that the email did not come from the source that states in From:, but I cannot say.

  • Man, it worked. Bcc came up blz. Thanks!

  • In a Gmail account was going to SPAM, but eh a test account. I did a test on my brother’s account and arrived at the inbox.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.