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
My Answer:
Unfortunately, in PHP, you cannot specify a custom sender email address using the `setFrom` method if you have not registered the sender email address. This is a security measure to prevent email spoofing.
One workaround is to set the sender name using the `setFrom` method and include the customer's email address in the body or subject of the email. For example:
php
$email->setFrom('Your Name <[email protected]>');
$email->setSubject('Contact Form Submission from ' . $customerEmail);
This way, the recipient will see the customer's email address in the email subject or body, even though the sender email address is your registered email address.
Alternatively, you can consider using a transactional email service like SendGrid or Mailgun, which allows you to send emails on behalf of your customers without registering their email addresses. These services provide APIs that allow you to specify custom sender email addresses.
Rate this post
4 of 5 based on 1309 votesComments