Doubt in Phpmailer

Asked

Viewed 93 times

1

I started using the PHPMailer, and is working but would like to know if there is how the sender is the email that the user typed in my form.

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

Follow the configuration 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;
  }

1 answer

2


Use this line

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

Whereas $emailFrom and $nameFrom are values that come from the form and you receive as variables.

  • I tested as requested and without success. The email I’m receiving is still me as sender.

  • You are using the Gmail server to send messages and the terms prohibit sending emails from outside the network. This line places the sender’s data in the "reply to" field in order to facilitate contact and identification.

  • Vlw! Tested here worked as you explained... But there is some way to receive the sender with the email that the user type?

  • This will depend on the provider. In this case, you use Gmail, so you can’t. If you used a provider that allowed, then just do something similar to this line: $mail->setFrom($emailFrom, $nameFrom);

  • Blz! Got it... Thank you very much asshole.

Browser other questions tagged

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