Phpmailer alternative Gmail From

Asked

Viewed 250 times

2

I have a website where there is a contact form.

The email sent by this form (Gmail), I use a specific only for the site (formulario@....), however, when sending to the client, set the parameter From as the contact email (contact@.... ), which is from Gmail as well (I configured it in the email account of the form so that it could sign as the contact).

When sending this email, I send a second email to the contact itself, but this, in turn, I’m trying to define as the customer’s email, but Gmail itself does not allow the sent email to be signed by a different email. Is there any alternative to that?

  • Email and password have been hidden

Code:

  $nomeCliente = $_POST['nome'];
  $emailCliente = $_POST['email'];
  $emailEmpresa = "[email protected]";
  $assuntoE1 = '=?UTF-8?B?'.base64_encode("Mil Blocos - Formulário do Website").'?=';
  $assuntoE2 = '=?UTF-8?B?'.base64_encode($_POST['assunto']).'?=';
  $mensagem = $_POST['mensagem'];

  $mail = new PHPMailer();
  $mail->isSMTP();
  $mail->CharSet = 'UTF-8';
  $mail->Host = 'smtp.gmail.com';
  $mail->SMTPAuth = true;
  $mail->Username = '[email protected]';
  $mail->Password = 'minhasenha';
  $mail->Port = 587;
  $mail->SMTPSecure = 'tls';
  $mail->setFrom($emailCliente, $nomeCliente);
  $mail->addAddress($emailEmpresa);
  $mail->Subject = $assuntoE2;
  $mensagem = 'E-mail do cliente: <br />' . $emailCliente . '<br /><br />' . 'Mensagem: <br />' . $mensagem;
  $mail->MsgHTML($mensagem);

  $mail->send();

2 answers

0

It has to be another set of code to send this. I’ve come across this problem and only managed to make another call in the class.

EDIT: After uploading, use the class ClearAddress(). After sending the first email, do this cleaning and put another recipient.

  • The problem itself is not in the class but in Gmail. Gmail that does not allow From to be changed..

  • So. Phpmailer has the addAddress, addCC and addBCC for OT submissions. From only part of a place. So I say you have to instantiate again to send that second email.

  • Yes, that I know. The problem is not to do the second sending of email, but to change the Gmail from. I want to send an email, but in another name/email. That’s what the setFrom function does, but it doesn’t work with Gmail emails.

  • Edited response with what I found later on the doc and in my codes.

0

Can you use another lib? Try the Swiftmailer: http://swiftmailer.org/

Another thing you can do is, instead of setting From, set Replyto. The email will be sent by the account form@... but the answers go to the contact@...

  • When you get home, I will be both and validate the answer. Thank you

  • Julyano is very likely that you won’t be able to set From in any / lib class. So I highly recommend that you consider setting Replyto.

  • I haven’t forgotten your answer. The project that I was applying, I had to use the mail() function, but in another project that I will use Phpmailer as well, I will have it in a second moment and give a feedback. Thank you

Browser other questions tagged

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