Sending e-mail with multiple senders and recipients

1

I have records in MySql , basically with columns:

usuario, emailusuario, descricao, responsavel, emailresponsavel .

I need to make a new registration, send an email to the user ( emailusuario ) and the responsible ( emailresponsavel ).

I use PHPMailer, with a Gmail account for the submissions, but the problem is, that the email arrives with sending email to the Gmail account and not with the sender's email would be what makes the new record), even setting $mail->SetFrom('[email protected]','usuario'); .

$mail->AddReplyTo() works normally.

I wonder if this occurs because it is authenticated by Gmail , because it is TLS , or some other reason, and if there is another way of doing it, the problem is PHPMailer . I need to do this, regardless of whether I have to change the SMTP or biblioteca .

Upload script:

require_once '/PHPMailer/PHPMailerAutoload.php';

$srvNome  = 'smtp.gmail.com';
$srvPort  = '587';
$srvEmail = '[email protected]';
$srvSenha = '****';

$emailAssunto       = 'NOVO REGISTRO';
$emailDestinatario  = $emailDest1; 
$titulo             = 'NOVO REGISTRO';

$conteudo = "teste";

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug  = 2;
$mail->SMTPAuth   = true;
$mail->SMTPSecure = 'tls';
$mail->SMTPOptions = array(
    'ssl' => array(
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
    )   
);
$mail->CharSet    = 'UTF-8';
$mail->Host       = $srvNome;
$mail->Port       = $srvPort;
$mail->Username   = $srvEmail;
$mail->Password   = $srvSenha;
$mail->AddReplyTo($emailRemetente,$remetenteNome);
$mail->SetFrom($emailRemetente,$remetenteNome);

$mail->IsHTML(true);
$mail->Subject    = $emailAssunto;
$mail->Body       = $conteudo;

$mail->AddAddress($emailDestinatario);

if(!$mail->Send()) echo 'erro';
    
asked by anonymous 05.03.2018 / 16:18

1 answer

2

For SMTP security issues (Gmail in case), the FROM tag will always be populated with the email of the SMTP authenticated account, that is, the gmail user in the case.

You will only be able to use it as intended if you mount your own SMTP server and send mail without SMTP authentication, via PHP's mail () function, via port 25. Currently most providers do not accept messages coming from port 25.

    
05.03.2018 / 16:25