How To Send Email from WordPress with SMTP (without a plugin)
Вставка
- Опубліковано 26 сер 2024
- Learn how to send email from your WordPress website without a plugin! Rather than adding YET ANOTHER plugin like WP Mail SMTP, you can configure your email settings in WordPress directly.
Code snippets and more at tonyteaches.te...
Check out my vlog channel @TonyFlorida
#wordpress #smtp
I was working on this issue today and I thought to myself "I wonder if Tony has a video on this." Thanks for all your help man!
Happy to help Rob! I'm glad you found me :)
This worked like a charm! Been racking my brain for almost six hours. Thanks Tony!
Glad it helped!
Thank you, a big help, the extra info regarding security in the comments is reassuring.
You're welcome!
Thank you!!!
Hello Tony, thanks! It worked perfectly. I don't have to use a plugin now
Great!!
Thanks so much man
No problem
Thank you very much, kind sir.
Can you show how do you capture the input values and call the wp_mail, please
Thank you for the tutorial. I have a question about security,, is it safe to store the password in clear text in wp-config?
A quick answer to your question is yes... this is an acceptable thing to do.
By default, WordPress also stores your database credentials in plain text in wp-config.php (see wordpress.org/support/article/editing-wp-config-php/). The reason for this is because WordPress needs to be given this information to interact with your database. Same thing for email like in this video.
You can obfuscate the password by encrypting it, but at some point, the password will need to be decrypted and reside in memory in plain text. At this point, if a hacker is on your server and looking at your wp-config file, you have bigger problems than your password being readable by a human.
The wp-config.php files is not accessible to your website visitors. The only people who should have access to this file are the website administrators.
From a security perspective, your job is to protect access to your server. To do this, strong passwords to WordPress, your database, and your sever are a good start.
@@TonyTeachesTech Thank you Tony! 🙏🏻
How to use mailtrap in our wordpress cms for email by contact form 7
Eres un "mostro"!! Really appreciate the time you take to share your knowledge. TY amigo!
I appreciate that!
Hello Tony, nice work, but I have a question, How can I use this if I have two different forms receiving message from two different emails?
Great tutorial Tony and with all the explanations. I'm a little bit concern with the password being visible at the wp-config.php. Isn't this somehow dangerous? I also want to avoid using more plugins.
Wooe great using phpmailer,,
Thank you,,
thank you for the informations , I just wanna ask you if there is a possibility to send email form a site in local
long live Tony. thank you man.
You're welcome!
Can't get it work under WP 6.1.1. Any ideas?
Hi Tony, nice video. except for some reason it didn't work for me. Any suggestion on why or what I can do?
GMAIL STOP the application less secure to send an email, this solution is not valid anymore, is there another way to send emails !!!
Tony is a great man ! Thanks ! :-)
No doubt!
So usefull thank you so much Tony :)
You're welcome!
it cant work .....this is not working on my site the setting
Can i put it on a snippet instead of Theme php?
i have code snippets installed
It is not working in my localhost in WordPress... is it possible to configure it in Localhost. Thanks
Would this method still work in sites using Oxygen Builder since it disables the theme completely?
great tutorial..... thanks
You're welcome!
Thank you so much !
You're very welcome!
Hi, will this work with Outlook? Will you do a tutorial for Outlook too? Thanks. This video is helpful.
Do you mean for an email address like you@outlook.com?
@@TonyTeachesTech Hi, yes. That is correct. Thanks and happy new year. :)
which one is better ?? 1 : use plugin to set SMTP settings or 2: add code to the files manually ???
I prefer to do this manually over a plugin
Thank you!
You're welcome!
some of the smtp plugins have logging as a feature. is there a way to set up email logging without a plugin?
Probably, but this would require a bit of work.
I don't actually see the benefit of logging in this case. All email communications will be stored on your email server, so I just see the logging feature as redundant.
Am I missing something here with logging?
Tony Teaches Tech yeh thought it could be complicated but thought i’d ask on the off chance it wasn’t. the purpose of logging would be to know if/when something fails. for example if for some reason the smtp server couldn’t be reached then at least you’d know.
@@EpithetMusicTV oh yes, good call. This information will always be available in the server logs in case you need to access it.
Thanks for this video! However, I have couple of queries.
I have installed wordpress using docker on GCP (ubuntu 16.04 LTS)⁶. The mail function isn't working in the docker image and I couldn't reset my password and I'm not receiving any notification mail from wordpress. I have 2 queries now:
1. What are 'SMTP_USER', 'SMTP_PASS' variables and how 'SMTP_USER' is different from 'SMTP_FROM' variable?
2. Will this approach work for a wordpress docker image? If not, what should I change? What would 'SMTP_PORT' be for a docker image?
SMTP_USER is your gmail address in this case. You'll want this to match SMTP_FROM (although they don't have to match, but spam filters might catch your email if they don't match).
This approach should work with a WordPress docker image.
Does that help? LMK if you have additional questions.
Thanks Man !!! Really appreciate your work.. You made me, subscribe your channel.. Haha
Thanks for subscribing!
Hi Tony, could you update this as in the new WP 6.1 and TwentyTwentyThree do not have a functions.php file. (P.S thanks for the 20$ for hetzner worked like a charm) .....Shaan
From name is not working please help
Hi Tony, thanks for your video, but after doing everything I still can see the 'Email Server problem shown on my website. I do not know why this happened? I need your help. Thanks.
Hmm, are you using Gmail with an app password?
I have a plugin which has set up the SMTP stuff and this is working for my wordpress generated emails. However, I want to code an email trigger in which sends an automatic email from the back-end. Can I use this code you are explaining to set up a SECOND SMTP connection or will it over-write what my plugin has already set up?
I'm not sure how to handle multiple connections, but I would think it's possible
Hi, i have integrated this in my wordpress. but i have separate core pages with forms in my wordpress. i want to call this configured function in each form separately. please suggest me how to use it.
I'm not sure I completely understand what you're trying to do. Do you want multiple SMTP settings?
I installed virtualmin (email server). What smtp should I fill in wordpress settings?
You'll need to provide the same type of information
I'll be creating a custom form that sends an email upon submission. Will the SMTP settings take effect if I use the wp_mail() function?
Yep
Hey I'm having trouble with the form, it won't send although it says "successfully sent". Does any additional code need to be in the form php file to reference the SMTP?
No extra code is necessary
Hello Tony, Pls I don't know if you can assist me of this my challenges.
My custom mails recently always remain in my outboxes, but if I tried to send mail through webmail, the emails will be sent out. I noticed this when I installed WP mail SMTP. And the config was conflicted
Sorry I don’t know
Great tutorial Tony. Everything is working fine. I have copied the code, added it in the correct files and changed the details and the mail came in within seconds!
Now I wanted to go a step further and create an admin page with fields where the values can be added (stored in db wp-options table). I want to load the values within the PHP Variables / Constants i.e.:
define( ‘SMTP_USER’, get_option( ‘smtp_user’ ) );
But as soon as I try this, the form is not sending anymore. It gets stuck at processing (using Ninja Forms) and results in an error which is logged in the console. When I revert back to add the values manually, everything is working fine. Do you perhaps have any idea what could be going wrong here?
I really hope you can help me out here.
Thanks in advance.
Sorry I don't know how I can help you
Hi, It will work to send WP emails such resetting password emails?
Yes it should
Like we use mail in php to send mail then what should I use to send mail manually through this function on a custom page inside my child theme?
Can you rephrase your question?
@@TonyTeachesTech I have set up a custom page that handles the custom registration form on the WordPress page. So I want to know how like in php as we write mail($to, $subject, $message, $headers) so with the function setup in the video what should I write instead of mail
One more question I have which I am struggling with and it's very important for me. If I am setting up my custom login in WordPress environment then how can I set the custom session variables and use it anywhere I want for example like:
session_start();
$_SESSION["email"] = $email
So the SMTP-Password has to be the password from the EMAIL-Account in use?
I would recommend to use an "app password" like this ua-cam.com/video/RbT28X0wiRw/v-deo.html (just the part where we create the Google App Password for you email)
what if i dont have to leave gmail credential in config file?
You will need your gmail credentials for this to work
I am working on custom email template. Can anyone tell me how to call this function?
I am using multiple email addresses for different purposes.
Are you using a plugin to do this?
will this work for outlook as well
Yes
Sir, how to go to the page that ur are initially in
Go to example.com/wp-admin (where example.com is your actual domain name)
@@TonyTeachesTech That link is not opening
@@indhu.v7938 Do you own the website? Are you sure it's WordPress?
What does mean send an email from a website?
From where to get SMTP info?
You can get that from you email provider
Thank you so much for the tutorial, but I can't send an HTML email? Is there a solution
Also when I want to reset the password with this method it doesn't work
Are you using Contact Form 7? There is a check box that you can see here ua-cam.com/video/lif0tW2UWvw/v-deo.html that says "Use HTML content type". I don't check it in the video, but if you check it you can send HTML emails.
I'm not sure why the password reset doesn't work. Are you talking about your WordPress admin password?
Thanks, Tony for the fast reply
I explained everything with screenshots here: codepen.io/mahmoud97/full/BazoMQa
I really hope you can help me if possible
Best regards
@@mahmoudmostafa5259 it doesn't look like the linked screenshots are working for me. I saw your writeup about not using Contact Form 7.
According to the WordPress docs for wp_mail (developer.wordpress.org/reference/functions/wp_mail/), "The default content type is text/plain which does not allow using HTML. However, you can set the content type of the email by using the ‘wp_mail_content_type’ filter."
Here's the WP docs for wp_mail_content_type developer.wordpress.org/reference/hooks/wp_mail_content_type/. Looks like you'll need to add something like this to your functions.php file:
function wpdocs_set_html_mail_content_type() {
return 'text/html';
}
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
@@TonyTeachesTech yes, this worked for me, thanks a lot Tony
@@mahmoudmostafa5259 I'm happy to hear that!
3:13 💀rip if anybody gains any kind of access to your wordpress server
Do you need the business plan to do this? The whole point of me watching this video was to avoid getting the business plan.
He has good ideas but the video does not work on my 2site
the fucking clickbait tho Jesus