phpmailer sends email to myself [closed]

1
<?php

require 'funcoes/PHPMailer-master/PHPMailerAutoload.php';

$email = $_POST['email'];

$nome = $_POST['nome'];

$titulo = $_POST['titulo'];

$mensagem = $_POST['mensagem'];



$mail = new PHPMailer;

$mail->SMTPDebug = 3;


$mail->isSMTP(); 

$mail->Host = 'smtp.gmail.com'; 


$mail->SMTPAuth = true; 


$mail->Username = 'meuemail';  


$mail->Password = 'senha';   


$mail->SMTPSecure = 'tls';     


$mail->Port = 587;         

$mail->From = $email; 

$mail->Sender = $email; 

$mail->FromName = $nome; 


$mail->AddAddress('meuemail', 'Milton Viziak');

$mail->AddAddress('meuemail');


$mail->Subject = $titulo;

$mail->Body    = $mensagem;


if(!$mail->send()) {

    echo 'Message could not be sent.';

    echo 'Mailer Error: ' . $mail->ErrorInfo;

} else {

    echo 'Message has been sent';
}

My question is why am I sending emails to min even if I put the from and sender with the email received in the form?

    
asked by anonymous 04.08.2015 / 13:32

1 answer

0

Try it this way, because if the email is invalid the email will not be sent:

$mail->SetFrom((filter_var($email, FILTER_VALIDATE_EMAIL) !== false) ? $email : 
'[email protected]' , (string) $nome);
//$mail->AddReplyTo((filter_var($email, FILTER_VALIDATE_EMAIL) !== false) ? $email : 
'[email protected]', (string) $nome);

//aqui o nome de quem envia
$mail->FromName = $nome; //nome de quem envia 

Correct the line below, since the user who should be the recipient of the message, correct?

$mail->AddAddress('[email protected]', 'Milton Viziak');

And delete this duplicate line below, unless you want to receive a copy:

// $mail->AddAddress('[email protected]');

And add these lines if you want to send them in HTML format:

$Email->WordWrap = 50;
$Email->IsHTML(true);
    
04.08.2015 / 16:17