phpmailer sends email to myself

Asked

Viewed 281 times

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 doubt is because I am sending email to me even if I place from and Sender with the email received in the form ?

  • the AddAddress can’t be your email, because AddAddress is the recipient, in this field inform the recipient you want, in case the return form.

  • but the addressee in the case is me. and as such informs the return of the form ?

  • You must put the variable $email in the $mail->AddAddress($email, 'Milton Viziak');

  • but the $email variable is just the email of the guy who filled out the form.

  • then, after all, to which email should be sent?

  • If the recipient is you of course you will receive the email yourself.

Show 1 more comment

1 answer

0

Try 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, because the user who must be the receiver 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 in HTML format:

$Email->WordWrap = 50;
$Email->IsHTML(true);
  • $mail->From = "[email protected]"; &#xA;$mail->FromName = "Ursula belchior";&#xA;//Define o destinatario&#xA;$mail->AddAddress('[email protected]', 'Milton Viziak');&#xA;&#xA;$mail->IsHTML(true); // Define que o e-mail será enviado como HTML&#xA;$mail->CharSet = 'iso-8859-1'; // Charset da mensagem (opcional)

  • In the email it does not appear in the sender the "[email protected]" it appears the [email protected].

  • and it was not supposed to appear the email from from there on the sender ? the name appears right Even now the email does not

  • Like I said, you’re reversing.

  • did it. It does not send any email.

  • Write in your question which are your emails 1.sender 2.receiver 3.reply, 4.system, because it seems that not even you know what you want. Have you read the code comments? You know the difference between sender and recipient?

  • sender = who sends the email | receiver / recipient = who receives the message | system = account that will make the delivery service | reply = which email will receive a reply from the receiver

  • I made the contact form. I took the name, the email, the title and the message. and this form will send to my email which is the linker83.only that I send the contact by the form.but only that I type any valid email and it does not appear. the only thing that appears is that it sends me anyway.

  • link. Look there my mistake and there in place of DE: Ursula Belchior is not that email I put another

  • I understand your problem, you want to receive the email as if it were from the client. So, just put the client’s email in Sender.

  • From what I’m seeing your setup was right, you’re typing that email into the contact form?

  • the email of the customer.

  • $mail->From = '[email protected]' $mail->Fromname = 'Ursula'; $mail->addAddress('[email protected]', 'Milton Viziak');

  • no From that is ta ta o miltonviziak but ta sending as if it were the Inker that ta equal in the image that I sent you. and by consiguration is to appear from: miltonviziak to:linker83

  • link my ta configured equal to that link

  • it didn’t work out the same thing.Could there be an error in the phpmailer class ? metedo Addaddress is overwriting the $From variable ?

Show 11 more comments

Browser other questions tagged

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