Doubt in PHPMailer

1

I started using PHPMailer , and it's working but I'd like to know if there's a way for the sender to be the email that the user entered on my form.

Note: It sends the form data field: name, subject, and message.

Here is the setting that is:

  $mail = new PHPMailer;

  $mail->isSMTP();
  $mail->Host = 'smtp.gmail.com';
  $mail->SMTPAuth = true;
  $mail->Username = '[email protected]';
  $mail->Password = 'senha';
  $mail->SMTPSecure = 'ssl';
  $mail->Port = 465;
  $mail->IsHTML(true);
  //$mail->FromName = 'teste';
  //$mail->From = '[email protected]';
  $mail->setFrom('[email protected]', 'teste');
  $mail->addAddress('[email protected]');
  $mail->Subject = 'E-mail PHPMailer';
  $mail->Body = '<h1>Mensagem enviada via PHPMailer</h1>';

  if($mail->Send()){
      echo 'Enviado com sucesso !';
  }else{
      echo 'Erro ao enviar Email:' . $mail->ErrorInfo;
  }
    
asked by anonymous 24.01.2017 / 03:57

1 answer

2

Use this line

$mail->AddReplyTo($emailFrom, $nameFrom);

Being $emailFrom and $nameFrom are values that come from the form and you get as variables.

    
24.01.2017 / 06:33