Sending email from your website (PHP mail)

The most common way to send email from your website is by using the PHP mail() function. PHP mail() is an easy to use email system built into the PHP programming language. It’s the default setting for almost all applications.

However, PHP mail is severely restricted on InfinityFree. To prevent spam and other abuse, most messages sent through PHP mail are rejected by the mail system. In practice, this means you cannot use PHP mail on InfinityFree to send your email.

If you want to send email from your website, the easiest option is to use an external SMTP service. Most applications offer a setting or plugin to send email with SMTP. We have written an article about how to send email with Gmail SMTP, which includes instructions on how to configure SMTP in your Gmail account and code samples to help you integrate SMTP in your own software.

Alternatively, you could consider to upgrade your account to premium hosting. With a premium hosting account, there are no filters on PHP mail() and the sending limits are much higher than on free hosting. So on premium hosting, you’ll be able to send professional looking email with ease.

6 Likes

A post was split to a new topic: Hosting Enquiry

Is there any other free and reliable external SMTP service from a trustworthy country, aside from Google? I’ve had a bad experience with Google as it locked me out of my own account multiple times for no reason.

Plenty of providers exist that provide free SMTP capabilities, many are even better for this purpose than Gmail.

Whether they are from a “trustworthy country” depends on which countries you find trustworthy.

5 Likes

I have my own domain, and my website is hosted on InfinityFree. The domain’s nameservers are pointed to InfinityFree. However, outgoing email with PHP’s mail() function is heavily restricted on InfinityFree. I would like to set up email addresses with my domain, such as [email protected], and I also want to add a contact form to my website.

  1. To set up an email address like [email protected], how can I do it? Do I need to use an external email provider like Zoho? Zoho requires adding a new TXT record and pasting the provided TXT value into the DNS configuration. How do I do that? Is this the correct way to configure email for my domain?
  2. If I have a contact form (e.g., Contact Form 7) on my website, how does it affect email functionality? Do I need to use a specific contact form plugin that sends emails via an SMTP server? Should I change to a different plugin for this?

You need to use SMTP for sending, yes.

TXT records are not supported on free hosting, verification needs to be done with CNAME records.

4 Likes

Thanks. I did it. I need to wait for this change to propagate. I hope it will work.

hi, if i use plugins like wp form, met form, etc i don’t receive any notification on my gmail as administrator, is it correct? how can i solve it?I use a free subdomain

Did you even read this article? It demostrates exactly that if you didn’t go through it it’s normal that you don’t recieve any emails, and only if you go through it can you recieve any email.

5 Likes

Are you using the same Gmail account to send and receive the email? If so, Gmail may be skipping the inbox and only storing the message in the Sent folder of your account. That’s a feature from Gmail, it’s not a problem with your code, and it definitely has nothing to do with our hosting. The solution is to not use the same email account to send and receive the email.

Alternatively, the email might not be sent correctly at all. The list of possible reasons for that is very, very long, and is not suitable for a comment to a general article. So if you’re having problems sending email with your website and the software you’re using to do so, please create a new topic in Hosting Support and describe the issue there.

5 Likes