Search code examples
phpemailsendgridsendgrid-api-v3

How to specify custom sender?


I'm using the $email->setFrom('[email protected]'); method and it's working fine for email delivered to the registered sender.

However, the email is delivered as [email protected]. How can I include the email of the customer that has filled the form? Eh: [email protected]?

If I replace $email->setFrom('[email protected]'); 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


Solution

  • 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("[email protected]");