Skip to content

How to set up email so your site's messages arrive

12 min read

Your site sends email at important moments: sign-in codes, password resets, comment notifications and welcome messages. Apps you add, such as a contact form, send through the same settings. This page shows how to set it up under Settings → Email, which sending method to choose, the SMTP settings for common providers, how to test, how to make sure messages reach the inbox, and what to do when they don't.

The screenshots are from Basehim 1.2.98.

What Basehim sends

EmailSent whenToTurned on or off in
Sign-in codeafter the password, when two-step verification applies to the accountthe account's emailSettings → Authentication, Two-step verification
Unlock codeafter repeated failed sign-ins pause password entry on an accountthe account's emailalways on
Password resetsomeone uses Forgot password?the account's emailalways on
Password changeda password is reset through the emailed linkthe account's emailalways on
Email address changedan account's email changes; with two-step verification the new address first gets a codethe old address (and the new one)always on
Welcomean account is created, by registration or by an administratorthe new personSettings → Authentication, off by default
New commenta comment is posted, with moderation linksthe administration email (Settings → General)Settings → Discussion
Reply to your commenta reply to someone's comment is approvedthe person who wrote the commentSettings → Discussion
Test emailyou press Send testyou—
Apps' emailwhatever the app does: form entries, reports, orderswhoever the app choosesthe app's own settings
Settings, Discussion: the two email notification switches
Comment emails are switched on and off under Settings → Discussion.
  1. A new comment emails the administration email (set under Settings → General), with links to approve or remove it.
  2. A reply emails the person who wrote the original comment, once the reply is visible.

Every email uses the same simple template with your site's name, so they look alike whatever sent them.

Before you require two-step verification: sign-in codes travel by email. Send a test first. If mail stops working while codes are required, see Locked out because codes don't arrive.

Quick start

  1. Open Settings → Email. A new site already sends as noreply@ its own domain, with PHP's mail().
  2. Press Send test. If the message reaches your inbox (not spam), you're done.
  3. If it doesn't arrive, or lands in spam, switch to SMTP with your host's mailbox or a sending service, and add the DNS records your provider gives you.

Settings → Email

Settings, Email: From email, From name, Send with, Save changes and Send a test email
Settings → Email on a new site.
  1. From email: the address your mail comes from. Use one on your site's own domain; left empty, Basehim uses noreply@ that domain.
  2. From name: the name people see next to it. Left empty, it follows your site's name, including when you rename the site.
  3. Send with: PHP mail() or SMTP (see Which method to use).
  4. Save changes. The test below always uses the saved settings, so save first.
  5. Send a test email to your own account's address.

The domain comes from your site's address, without www., as it was saved when you installed Basehim. Links in emails, such as password reset links, are built from the same address. If the site's address isn't a public domain, the screen says so and there is no automatic sender: type a From email.

The From address

Mail servers check that a message really comes from the domain in its From address. Sending as a Gmail, Outlook or Yahoo address through your own server fails that check, so the message is refused or filed as spam, and sign-in codes and password resets with it. Basehim warns when the From address isn't on your domain:

A warning that emails are sent from a gmail.com address, which isn't on this site's domain
A From address on someone else's domain.
  1. The warning names the address in use and suggests one on your domain.
  2. The From email that caused it. Change it to an address on your domain, or send through that provider's own SMTP server (for Gmail, see providers).

The address doesn't need to be a real mailbox for PHP mail(), but replies go nowhere. If people may reply, use an address someone reads, or let apps set a Reply-To.

Which method to use

PHP mail()SMTP
How it worksHands the message to the web server's own mail programSigns in to a mail server, like an email app does, and sends through it
SetupNothing: the defaultA host, port, encryption, username and password
Reaches the inboxOften, on hosts that sign mail for your domain (most cPanel hosts do)More reliably: the provider signs and sends it
Error messagesOnly "mail() returned false"; the reason is in the server's mail logThe mail server's own answer, shown in the test result
Good forA new site, light mail, a host with email for your domainSign-in codes for many people, comment-heavy sites, apps that send a lot

When PHP mail() sends from your own domain, Basehim also tells the server to use your From address for bounced messages, so they come back to you rather than to your hosting account.

Sending through SMTP

Choose SMTP in Send with and the server details appear.

The SMTP settings: host, port, encryption, username, a saved password and the switch to remove it
SMTP, filled in and saved.
  1. Send with: SMTP.
  2. SMTP host: the server name your provider gives you.
  3. Port: usually 587 or 465.
  4. Encryption must match the port: STARTTLS for 587, SSL for 465. None only for a server on the same machine or network.
  5. Username: usually the full email address, or what your provider names (SendGrid's is the word apikey).
  6. Password: never shown again once saved. Leave it empty to keep it, or type a new one to replace it.
  7. Remove the saved password, for example when you switch to a server that doesn't sign in.

Basehim connects, upgrades to an encrypted connection when STARTTLS is chosen, signs in with the username and password, and sends. It waits up to 15 seconds for the server at each step. There is no queue: mail is sent while the page that triggered it is answered, so a slow server slows that page down.

Settings for common providers

These are the providers' published settings at the time of writing; their own help pages have the final word.

ProviderSMTP hostPort and encryptionUsernamePassword
Your host's mailbox (cPanel, Plesk, DirectAdmin)as the control panel's email client settings show, often mail.yourdomain.com465 SSL, or 587 STARTTLSthe full mailbox addressthe mailbox's password
Gmail, Google Workspacesmtp.gmail.com587 STARTTLS, or 465 SSLyour full addressan app password. The account needs 2-Step Verification; a normal password is refused
Microsoft 365smtp.office365.com587 STARTTLSthe mailbox addressthe mailbox password, while Microsoft still allows it (see the note below)
Zoho Mailsmtp.zoho.com; smtppro.zoho.com for paid plans with your own domain465 SSL, or 587 STARTTLSyour addressyour password, or an app-specific password with two-factor on
Amazon SESemail-smtp.region.amazonaws.com587 STARTTLS, or 465 SSLthe SMTP username from the SES consoleits SMTP password. IAM access keys don't work
SendGridsmtp.sendgrid.net587 STARTTLS, or 465 SSLthe word apikeyan API key with Mail permission
Mailgunsmtp.mailgun.org; smtp.eu.mailgun.org for EU domains587 STARTTLSthe domain's SMTP login, such as postmaster@mg.yourdomain.comits SMTP password
Brevosmtp-relay.brevo.com587 STARTTLS, or 465 SSLthe SMTP login on Brevo's SMTP & API pagean SMTP key (not an API key)
Postmarksmtp.postmarkapp.com587 STARTTLSthe server API tokenthe same token
  • Gmail sends up to about 500 messages a day from a personal account and 2,000 from Workspace. Fine for sign-in codes, not for a busy site.
  • Microsoft 365 is retiring password sign-in for SMTP. It is planned to be off by default for existing organisations from the end of December 2026, and new organisations won't get it at all. Basehim signs in with a password, so when that happens the test fails with 550 5.7.30 Basic authentication is not supported. Use a sending service, or your host's mailbox, instead.
  • Sending services (SES, SendGrid, Mailgun, Brevo, Postmark) first ask you to verify your domain with a few DNS records. Until then they may refuse your From address, or send only to verified addresses (Amazon SES starts in a sandbox).
  • Port 25 is blocked by most hosting and cloud providers for outgoing mail. Use 587 or 465; some services also offer 2525.

Send a test email

Send test sends a message to the email address of the account you are signed in with, using the saved settings. The result appears at the top of the screen:

Test email sent to maria@example.org, check the inbox and spam folder
The server accepted the message.
  1. Accepted means the mail server took the message, not that it reached the inbox. Check the inbox and the spam folder. If it is in spam, see Getting into the inbox.
The test email: the site name, It works!, a line saying which driver sent it, and the footer
The test email, in the template every Basehim email uses.
  1. Your site's name.
  2. The heading: It works! The subject line is Basehim test email.
  3. The message, ending with the method that sent it, and for SMTP the server and port.
  4. The footer: You're receiving this email from your site.

When sending fails, the result says what the mail server answered:

Test email failed: SMTP authentication failed: 535 5.7.8 Invalid user name or password
The server refused to sign in.
  1. Basehim's step (SMTP authentication failed), then the mail server's own answer. Troubleshooting lists what each one means.

Getting into the inbox

Gmail, Outlook and Yahoo decide whether to trust a message by checking DNS records on the From address's domain. Since 2024, Gmail and Yahoo require every sender to pass SPF or DKIM, and bulk senders all three. You add these records where your domain's DNS is managed: your host's control panel, your registrar or Cloudflare.

RecordWhat it saysExample
SPF (TXT on example.org)which servers may send mail for the domain. Only one SPF record per domain: add each provider to it.v=spf1 a mx include:_spf.google.com ~all
DKIM (TXT or CNAME, name from the provider)a signature key, so receivers can check the message wasn't forged or changedgiven by your host or sending service
DMARC (TXT on _dmarc.example.org)what to do with mail that fails SPF and DKIM, and where to send reports. Start with p=none and tighten later.v=DMARC1; p=none; rua=mailto:dmarc@example.org
  • cPanel has an Email Deliverability page that checks SPF and DKIM for each domain and can add the records for you when the domain's DNS is on the same server.
  • Sending services show the exact SPF and DKIM records to add when you verify your domain.
  • Check a delivered message: in Gmail, open it and choose Show original. SPF, DKIM and DMARC should each say PASS.
  • Keep the From address on the domain the records are for, as Basehim suggests.

Where failures are recorded

Every email that fails to send, from core or an app, is written to the site's log with the reason and the recipient. Open System → Logs and choose the day:

System, Logs: today's log file with an ERROR line, Mail send failed: SMTP authentication failed
System → Logs.
  1. The log for the day you choose.
  2. An ERROR: Mail send failed: line with the server's answer and the address it was for. A password reset that never arrived leaves one of these.

Apps' mail is also recorded in the app's own log (Apps → the app → Logs), as Sent mail or Mail failed with the subject. A PHP mail() that the server accepts but later drops leaves nothing here; your host's mail log, or the mailbox's bounce messages, will show it.

Troubleshooting

The test saysWhat it means and what to do
PHP mail() returned false — check the server mail log.The server has no working mail program, or mail() is disabled. Ask your host, or use SMTP.
SMTP connect failed: Connection refused or timed outWrong host or port, or your host blocks outgoing connections on that port. Check both; try the other of 587 and 465; ask your host whether outgoing SMTP is allowed, or use their own mailbox.
SMTP greeting failed, or a long wait before an errorThe encryption doesn't match the port: SSL on 465, STARTTLS on 587.
STARTTLS refusedThis port doesn't offer STARTTLS. Use SSL on 465, or check the port.
TLS negotiation failed.The server's certificate doesn't match the host name you typed, or is invalid. On shared hosting use the server's own name from the control panel instead of mail.yourdomain.com.
AUTH LOGIN not acceptedThe server won't take a password on this connection: it may need encryption first, or accept only OAuth sign-in (Microsoft 365 after basic authentication is retired).
SMTP authentication failed: 535 …Wrong username or password. Gmail needs an app password (534-5.7.9 Application-specific password required); SendGrid's username is apikey; SES needs its SMTP credentials, not IAM keys.
MAIL FROM rejectedThis account may not send as the From address. Use the mailbox's own address, or verify the domain or sender with your provider.
Recipient rejectedThe address is wrong, or the server won't relay without signing in: check the username and password are saved.
Message rejected: …The server took the details but refused the message, often a sending limit or a policy. Its answer says which.
Cancelled by mail.before_send filter.An app stopped the message on purpose. Check which apps you have switched on under Apps.
Sent, but nothing arrivesLook in spam, check the address on your account, add SPF and DKIM, and try SMTP. With mail(), ask your host for the mail log.
Links in emails go to the wrong addressThe site's address was saved wrongly when you installed. It can't be changed from the dashboard yet: ask your host to correct APP_URL in Basehim's .env file.

Locked out because codes don't arrive

If two-step verification is required and mail has stopped working, nobody can finish signing in. To get back in, open your hosting control panel's File Manager, go into Basehim's storage folder and create an empty file named disable-2fa. If you can't, ask your host to do it. This suspends two-step verification for everyone. Sign in, fix and test mail, then delete the file: Settings → Authentication shows a warning for as long as it exists.

The SMTP password

  • It is stored with the site's other settings in the database, and never sent back to the browser: the screen shows only that one is saved.
  • AI assistants and other programs connected to your site never see it, whatever access you gave them.
  • Prefer a credential made for sending only: an app password, an SMTP key or a sending-only API key, rather than your main email password. You can revoke it without changing anything else.
  • Only people who may change settings can open Settings → Email.

Limits

  • No second try. Each email is sent the moment something triggers it. If sending fails, it isn't tried again; the log keeps the failure.
  • Password sign-in only. SMTP signs in with a username and password. The newer sign-in method Microsoft 365 is moving to isn't supported.
  • No attachments. Emails link to files instead.
  • One template for all emails, with the site's name. There is no editor for the wording of core's emails.
  • No sent-mail history in the admin: only failures are logged.

Next: Back to the Guide

Need more help?

Every step of running your site, in order, with screenshots.

Discussion

Leave a comment