Sending email with multiple senders and recipients

Asked

Viewed 254 times

0

I have records on MySql, basically with columns:

usuario, emailusuario, descricao, responsavel, emailresponsavel.

I need, when a new registration is made, send an email to the user himself (emailusuario) and to the responsible (emailresponsavel).

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

The $mail->AddReplyTo() works normally.

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

Sending 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';

1 answer

1


For security reasons of SMTP (Gmail in the case), the FROM tag (From:) will always be filled with the email of the account authenticated in SMTP, ie of 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 email without authentication in SMTP, via PHP mail() function, via port 25. Currently most providers do not accept messages from port 25.

Browser other questions tagged

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