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

КОМЕНТАРІ • 107

  • @robw1138
    @robw1138 Рік тому +3

    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!

  • @mediabytaylor2771
    @mediabytaylor2771 2 роки тому +4

    This worked like a charm! Been racking my brain for almost six hours. Thanks Tony!

  • @shannonandmattsopenmic3257
    @shannonandmattsopenmic3257 3 роки тому +2

    Thank you, a big help, the extra info regarding security in the comments is reassuring.

  • @bobulele
    @bobulele Місяць тому

    Thank you!!!

  • @sureshbhatt363
    @sureshbhatt363 3 роки тому +1

    Hello Tony, thanks! It worked perfectly. I don't have to use a plugin now

  • @adesojiadesesan826
    @adesojiadesesan826 3 місяці тому

    Thanks so much man

  • @phkoon
    @phkoon 2 місяці тому

    Thank you very much, kind sir.

  • @pablopodgaiz5853
    @pablopodgaiz5853 4 місяці тому

    Can you show how do you capture the input values and call the wp_mail, please

  • @humaidalali4903
    @humaidalali4903 3 роки тому +7

    Thank you for the tutorial. I have a question about security,, is it safe to store the password in clear text in wp-config?

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому +4

      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.

    • @humaidalali4903
      @humaidalali4903 3 роки тому +1

      @@TonyTeachesTech Thank you Tony! 🙏🏻

    • @AbhishekSharma-eo1xe
      @AbhishekSharma-eo1xe 3 роки тому

      How to use mailtrap in our wordpress cms for email by contact form 7

  • @frankalvarez7513
    @frankalvarez7513 3 роки тому

    Eres un "mostro"!! Really appreciate the time you take to share your knowledge. TY amigo!

  • @cristianpacher
    @cristianpacher 6 місяців тому

    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?

  • @VascoDanielBaiao
    @VascoDanielBaiao 10 місяців тому

    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.

  • @alfanur_rizal
    @alfanur_rizal Рік тому

    Wooe great using phpmailer,,
    Thank you,,

  • @simsworld249
    @simsworld249 2 роки тому

    thank you for the informations , I just wanna ask you if there is a possibility to send email form a site in local

  • @rafi_45
    @rafi_45 3 роки тому

    long live Tony. thank you man.

  • @radomirangelov3070
    @radomirangelov3070 Рік тому +1

    Can't get it work under WP 6.1.1. Any ideas?

  • @lifechangingwords7466
    @lifechangingwords7466 Рік тому

    Hi Tony, nice video. except for some reason it didn't work for me. Any suggestion on why or what I can do?

  • @atefjaballah2190
    @atefjaballah2190 2 роки тому

    GMAIL STOP the application less secure to send an email, this solution is not valid anymore, is there another way to send emails !!!

  • @MrStefanica
    @MrStefanica 2 роки тому

    Tony is a great man ! Thanks ! :-)

  • @expertcoder3101
    @expertcoder3101 3 роки тому

    So usefull thank you so much Tony :)

  • @smartnon9129
    @smartnon9129 2 місяці тому

    it cant work .....this is not working on my site the setting

  • @brunob1748
    @brunob1748 2 роки тому

    Can i put it on a snippet instead of Theme php?
    i have code snippets installed

  • @virtuallyshow6782
    @virtuallyshow6782 Рік тому

    It is not working in my localhost in WordPress... is it possible to configure it in Localhost. Thanks

  • @gashumba888
    @gashumba888 2 роки тому

    Would this method still work in sites using Oxygen Builder since it disables the theme completely?

  • @RespinaCollege
    @RespinaCollege 3 роки тому

    great tutorial..... thanks

  • @youterisim6173
    @youterisim6173 3 роки тому

    Thank you so much !

  • @mazwenb5783
    @mazwenb5783 3 роки тому +1

    Hi, will this work with Outlook? Will you do a tutorial for Outlook too? Thanks. This video is helpful.

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому +1

      Do you mean for an email address like you@outlook.com?

    • @mazwenb5783
      @mazwenb5783 3 роки тому

      @@TonyTeachesTech Hi, yes. That is correct. Thanks and happy new year. :)

  • @RespinaCollege
    @RespinaCollege 3 роки тому

    which one is better ?? 1 : use plugin to set SMTP settings or 2: add code to the files manually ???

  • @rodrigoscustodio
    @rodrigoscustodio 3 роки тому

    Thank you!

  • @EpithetMusicTV
    @EpithetMusicTV 3 роки тому +1

    some of the smtp plugins have logging as a feature. is there a way to set up email logging without a plugin?

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      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?

    • @EpithetMusicTV
      @EpithetMusicTV 3 роки тому

      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.

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      @@EpithetMusicTV oh yes, good call. This information will always be available in the server logs in case you need to access it.

  • @shivakumarpanaganti258
    @shivakumarpanaganti258 3 роки тому +1

    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?

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому +1

      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.

  • @bishalbanerjee8109
    @bishalbanerjee8109 3 роки тому

    Thanks Man !!! Really appreciate your work.. You made me, subscribe your channel.. Haha

  • @MarineHobby
    @MarineHobby Рік тому

    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

  • @Digital_Life96
    @Digital_Life96 7 місяців тому

    From name is not working please help

  • @fangcui655
    @fangcui655 3 роки тому

    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.

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      Hmm, are you using Gmail with an app password?

  • @JK-pr3lu
    @JK-pr3lu 3 роки тому

    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?

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      I'm not sure how to handle multiple connections, but I would think it's possible

  • @mahendravarma22
    @mahendravarma22 3 роки тому

    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.

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      I'm not sure I completely understand what you're trying to do. Do you want multiple SMTP settings?

  • @AgarioSplitrunner
    @AgarioSplitrunner 3 роки тому

    I installed virtualmin (email server). What smtp should I fill in wordpress settings?

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      You'll need to provide the same type of information

  • @emulatorgamer6325
    @emulatorgamer6325 3 роки тому

    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?

  • @oktaycinpolat421
    @oktaycinpolat421 3 роки тому

    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?

  • @olulovejaphet
    @olulovejaphet 2 роки тому

    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

  • @daanx6154
    @daanx6154 2 роки тому

    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.

  • @JuanMiguelEspinalJimenez
    @JuanMiguelEspinalJimenez Рік тому

    Hi, It will work to send WP emails such resetting password emails?

  • @rohansharma6136
    @rohansharma6136 3 роки тому

    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?

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      Can you rephrase your question?

    • @rohansharma6136
      @rohansharma6136 3 роки тому

      @@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

    • @rohansharma6136
      @rohansharma6136 3 роки тому

      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

  • @masterbruce7592
    @masterbruce7592 3 роки тому

    So the SMTP-Password has to be the password from the EMAIL-Account in use?

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому +1

      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)

  • @darshaim
    @darshaim 3 роки тому

    what if i dont have to leave gmail credential in config file?

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      You will need your gmail credentials for this to work

  • @JayPancholi
    @JayPancholi 3 роки тому

    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.

  • @Daviirose3
    @Daviirose3 2 роки тому

    will this work for outlook as well

  • @indhu.v7938
    @indhu.v7938 3 роки тому

    Sir, how to go to the page that ur are initially in

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      Go to example.com/wp-admin (where example.com is your actual domain name)

    • @indhu.v7938
      @indhu.v7938 3 роки тому

      @@TonyTeachesTech That link is not opening

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      @@indhu.v7938 Do you own the website? Are you sure it's WordPress?

  • @VSongu
    @VSongu Рік тому

    What does mean send an email from a website?

  • @ukeditz690
    @ukeditz690 3 роки тому

    From where to get SMTP info?

  • @mahmoudmostafa5259
    @mahmoudmostafa5259 3 роки тому

    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

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому +1

      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?

    • @mahmoudmostafa5259
      @mahmoudmostafa5259 3 роки тому

      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

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому +1

      @@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' );

    • @mahmoudmostafa5259
      @mahmoudmostafa5259 3 роки тому

      @@TonyTeachesTech yes, this worked for me, thanks a lot Tony

    • @TonyTeachesTech
      @TonyTeachesTech  3 роки тому

      @@mahmoudmostafa5259 I'm happy to hear that!

  • @jacksoncremean1664
    @jacksoncremean1664 2 роки тому

    3:13 💀rip if anybody gains any kind of access to your wordpress server

  • @Ryeburnyard
    @Ryeburnyard Рік тому

    Do you need the business plan to do this? The whole point of me watching this video was to avoid getting the business plan.

    • @smartnon9129
      @smartnon9129 2 місяці тому

      He has good ideas but the video does not work on my 2site

  • @exi8965
    @exi8965 2 роки тому

    the fucking clickbait tho Jesus