wp_mail() function

Started by Stranger, Jul 20, 2022, 03:00 PM

Previous topic - Next topic

StrangerTopic starter

My hosting provider prohibits the use of the wp_mail() function, or rather, it is somehow configured incorrectly.
phpmail doesn't work either, port 25 is closed.
Perhaps someone has experienced something similar?
At the initial stage, I need to send up to ten letters a day, then this number will grow.
I have already thought about somehow organizing sending through a regular mail service, but I don't know how to do it better.
  •  

Ali_Pro

Not the best way - sending mail using php. Here your letters go through all the filters and the provider's servers, and the loss or non-delivery of the letter is very likely. A frequent occurrence with small providers.

Today, the most correct way is to send via a major postal service (google, outlook, etc). Mail goes through a channel protected by encryption methods to the mail sending server directly from your php script. As far as I understand, you have Wordpress?
In this case, it's an easy task.
WPMail SMTP. Install this plugin. Choose the desired mail service.
There will be questions - contact me.
Ali.
  •  

StrangerTopic starter

I installed the plugin, and tried to enter my password and login from my Google account. The account was registered many years ago.
But for some reason the plugin is not working. Not even a connection.
I tried many times. I'm probably doing something wrong.
  •  

Ali_Pro

Yes, you made a mistake. ;)  The most classic. And she is terrible!  ;D
You didn't read the instructions.
We are not working with your mailbox access settings, in this case we are using Google Workspace account via the Google API.
It is important!
Please carefully read the section on working with the Google Workspace account, the authors of the plugin very punctually described the entire mechanism of action. I think if you do everything according to the points, and this is not a big deal, then everything will work out.
Here is the link in the plugin:

You cannot view this attachment.

After completing the setup, do not forget to send a test email to any address. The function is located on the 2nd tab of the plugin settings.
Ali.
  •  

Ali_Pro

This is how the received test email will look like. If the test passes, it means that you are already using on your site all the benefits of working through Google's powerful SMTP. Additionally, I recommend looking at section on SPF and DKIM.You cannot view this attachment.
Ali.
  •  

StrangerTopic starter

I finally figured out how to create a WEB application in the Cloud Console. Enabled Gmail API for my project. Got the client ID and secret and switched the application from to external mode. I inserted the ID and secret into WP Mail SMTP, everything worked right away.
Learned a lot.
Thank you, it really helped me!
  •  

Ali_Pro

Please.  :)
By the way, the plugin has the ability to work not only with the API of the service, but also as a simple mail client with the usual SMTP authorization via STARTTLS on port 25 or TLS on port 465.
Ali.
  •  

_AnnA_

Quote from: Ali_Pro on Jul 22, 2022, 10:01 AMBy the way, the plugin has the ability to work not only with the API of the service, but also as a simple mail client with the usual SMTP authorization via STARTTLS on port 25 or TLS on port 465.

I use this plugin for domain mail on byethost.com. Everything suits me in the hoster, but they have SMTP sending disabled. The plugin allows you to bypass this limitation. I don't use the API, the plugin just connects to gmail as a trusted one.
The option you are writing about.
  •  

infibeam

wp_mail() is a pluggable function. That function is used to send emails. Anywhere in WordPress, when sending an email, it uses this feature. So, the setup can be very interesting. For example, you can use the default html template for all emails sent from your WordPress installation.
You can also send a BCC copy of each message to a specific email address to have a kind of backup (believe me, this can be useful when someone tells you that they didn't receive the message!).

The default email type is text/plain, which means that html tags cannot be used in the body of the mail.
You can change the email type through the wp_mail_content_type filter or by specifying the header: content-type: text/html.
The default encoding corresponds to the encoding of the blog (usually utf-8). The encoding is set via the wp_mail_charset filter.
  •