0

I'm using the $email->setFrom('no-reply@example.com'); method and it's working fine for email delivered to the registered sender.

However, the email is delivered as no-reply@example.com. How can I include the email of the customer that has filled the form? Eh: mario@gmail.com?

If I replace $email->setFrom('mario@gmail.com'); I will get 403.

This happen because I have to register the sender. But I just need to create a simple contact form.

Is there a way to use setFrom using a custom email?

Thanks in advance

sfarzoso
  • 1,356
  • 2
  • 24
  • 65
  • 2
    _"How can I include the email of the customer that has filled the form?"_ - you don't want to do that, it will increase the possibility of your mail getting classified as spam by a lot. See https://stackoverflow.com/a/24644450/1427878, section titled "Don't use a faux From: sender" – CBroe Oct 01 '21 at 06:36

1 Answers1

3

Twilio SendGrid developer evangelist here.

When sending emails with SendGrid you do need to verify the email or domain you are sending from. So, you can't use any email address as the from email.

You're creating a contact form, which is why you want the email to appear to come from the person sending it. However, what you really want from that is to be able to reply straight to the person that sent the email.

What you can do is send the email from a domain or email address you have verified and then set the reply-to header to the user's email address. You will receive the email from your chosen email address but when you go to reply the to address will be filled in with the custom email address.

$email->setReplyTo("mario@gmail.com");
philnash
  • 70,667
  • 10
  • 60
  • 88
  • Exactly what I was looking for... my code is in C# but it was easy to adjust. Thank you so much! – nrod Jul 13 '22 at 11:36