Emails Not Being Sent

I’m encountering an issue with email delivery in OJS 3.3.4. When a user signs up, registration confirmation emails, as well as password change emails, are not being delivered. I found the following error message in logs:

stream_socket_enable_crypto(): Peer certificate CN=webserver.example.com' did not match expected CN=smtp.gmail.com’.

default = smtp
smtp = On
smtp_server = smtp.gmail.com
smtp_port = 587
smtp_auth = tls
smtp_username = name@example.com
smtp_password = ******

Both the Principal Contact and Support Contact email addresses are set to name@example.com.
Testing SMTP with online tools successfully delivers emails.
My site domain where OJS is hosted is my.example.com not example.com.

Despite successful SMTP testing with online tools, emails are not being delivered to users through OJS.
What could be causing this error?

Have you tried the “two-factor authentication” method?
This method seems to be the solution for many people.

Thanks for your response,

I already tried that, but it’s still not working.
Do you think the issue could be because the site domain (my.example.com) and the email domain (example.com) are different? Any other ideas on what might be causing this?

Given that you’re using smtp.gmail.com to send emails, whether the site is installed on the main domain or a subdomain shouldn’t be an issue. Nonetheless, I suggest examining the PHP error codes for additional troubleshooting.

By the way your OJS version 3.3.x or 3.4?
There is no version 3.3.4

This is the error that I get when email isn’t sent Unable to connect with STARTTLS: stream_socket_enable_crypto(): Peer certificate CN=webserver.example.com' did not match expected CN= smtp.gmail.com’.
are you referring to something else?

Yes, I meant 3.4
Thanks

I will check on my server for 3.4 and let you know.

It worked without any problem on my server.

here is my config email settings:

[email]
; Default method to send emails
; Available options: sendmail, smtp, log, phpmailer
default = smtp
; Path to the sendmail, -bs argument is for using SMTP protocol
sendmail_path = "/usr/sbin/sendmail -bs"
; Use SMTP for sending mail instead of mail()
smtp = On
; SMTP server settings
smtp_server = smtp.gmail.com
smtp_port = 587
; Enable SMTP authentication
; Supported smtp_auth: ssl, tls (see PHPMailer SMTPSecure)
smtp_auth = tls
smtp_username = testojsmail@gmail.com

smtp_password = App Password is a **16-digit passcode not an email password**

Don’t ignore this settings


I received email

Thank you for doing that.

I have the same exact configuration with email 2FA and a 16-digit passcode, except my SMTP username is not a Gmail address; it is an example.com email address. I don’t know if this affects anything.

I changed something:
The domain where OJS is installed is my.example.com. When I use my.example.com:465 for the SMTP configuration (instead of smtp.gmail.com), the SMTP username is name@my.example.com. This email is also my principal and support contact.

For temporary emails with less protection, when I sign up users with them, they receive emails from OJS, but Gmail users don’t. Also, the error logs only show PHP deprecated logs and not errors like before, even if the email isn’t received by the Gmail user. Is it because my.example.com isn’t verified or something? Does this have to do with SPF, DKIM, or other email authentication methods?

Thanks again.

I recommend checking your SPF and DKIM settings to ensure Gmail users receive your emails. These methods help prevent emails from being marked as spam. Additionally, using your primary domain (name@example.com) is more reliable than using a subdomain (name@my.example.com).

For more information on Gmail SMTP settings and managing outbound gateway usage, you can refer to this link: Google Support.