How To Send Email from WordPress with SMTP (without a plugin)

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 2025

ความคิดเห็น • 107

  • @robw1138
    @robw1138 2 ปีที่แล้ว +4

    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!

    • @TonyTeachesTech
      @TonyTeachesTech  ปีที่แล้ว

      Happy to help Rob! I'm glad you found me :)

  • @mediabytaylor2771
    @mediabytaylor2771 2 ปีที่แล้ว +4

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

  • @humaidalali4903
    @humaidalali4903 4 ปีที่แล้ว +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  4 ปีที่แล้ว +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 4 ปีที่แล้ว +1

      @@TonyTeachesTech Thank you Tony! 🙏🏻

    • @AbhishekSharma-eo1xe
      @AbhishekSharma-eo1xe 3 ปีที่แล้ว

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

  • @shannonandmattsopenmic3257
    @shannonandmattsopenmic3257 4 ปีที่แล้ว +2

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

  • @Elpodpod
    @Elpodpod 8 หลายเดือนก่อน

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

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

  • @cristianpacher
    @cristianpacher 10 หลายเดือนก่อน

    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?

  • @radomirangelov3070
    @radomirangelov3070 2 ปีที่แล้ว +1

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

  • @brunob1748
    @brunob1748 2 ปีที่แล้ว

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

  • @sureshbhatt363
    @sureshbhatt363 3 ปีที่แล้ว +1

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

  • @virtuallyshow6782
    @virtuallyshow6782 ปีที่แล้ว

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

  • @lifechangingwords7466
    @lifechangingwords7466 2 ปีที่แล้ว

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

  • @VascoDanielBaiao
    @VascoDanielBaiao ปีที่แล้ว

    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.

  • @gashumba888
    @gashumba888 2 ปีที่แล้ว

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

  • @frankalvarez7513
    @frankalvarez7513 3 ปีที่แล้ว

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

  • @rafi_45
    @rafi_45 3 ปีที่แล้ว

    long live Tony. thank you man.

  • @MrStefanica
    @MrStefanica 3 ปีที่แล้ว

    Tony is a great man ! Thanks ! :-)

  • @EpithetMusicTV
    @EpithetMusicTV 4 ปีที่แล้ว +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  4 ปีที่แล้ว

      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 4 ปีที่แล้ว

      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  4 ปีที่แล้ว

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

  • @phkoon
    @phkoon 7 หลายเดือนก่อน

    Thank you very much, kind sir.

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

  • @expertcoder3101
    @expertcoder3101 3 ปีที่แล้ว

    So usefull thank you so much Tony :)

  • @mazwenb5783
    @mazwenb5783 4 ปีที่แล้ว +1

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

    • @TonyTeachesTech
      @TonyTeachesTech  4 ปีที่แล้ว +1

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

    • @mazwenb5783
      @mazwenb5783 4 ปีที่แล้ว

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

  • @Daviirose3
    @Daviirose3 3 ปีที่แล้ว

    will this work for outlook as well

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

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

  • @JuanMiguelEspinalJimenez
    @JuanMiguelEspinalJimenez 2 ปีที่แล้ว

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

  • @mahendravarma22
    @mahendravarma22 4 ปีที่แล้ว

    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  4 ปีที่แล้ว

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

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

  • @olulovejaphet
    @olulovejaphet 3 ปีที่แล้ว

    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

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

  • @alfanur_rizal
    @alfanur_rizal 2 ปีที่แล้ว

    Wooe great using phpmailer,,
    Thank you,,

  • @smartnon9129
    @smartnon9129 6 หลายเดือนก่อน

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

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

  • @RespinaCollege
    @RespinaCollege 3 ปีที่แล้ว

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

    • @TonyTeachesTech
      @TonyTeachesTech  3 ปีที่แล้ว

      I prefer to do this manually over a plugin

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

  • @adesojiadesesan826
    @adesojiadesesan826 7 หลายเดือนก่อน

    Thanks so much man

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

  • @MarineHobby
    @MarineHobby 2 ปีที่แล้ว

    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

  • @bobulele
    @bobulele 5 หลายเดือนก่อน

    Thank you!!!

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

  • @RespinaCollege
    @RespinaCollege 3 ปีที่แล้ว

    great tutorial..... thanks

  • @daanx6154
    @daanx6154 3 ปีที่แล้ว

    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.

    • @TonyTeachesTech
      @TonyTeachesTech  3 ปีที่แล้ว

      Sorry I don't know how I can help you

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

  • @masterbruce7592
    @masterbruce7592 4 ปีที่แล้ว

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

    • @TonyTeachesTech
      @TonyTeachesTech  4 ปีที่แล้ว +1

      I would recommend to use an "app password" like this th-cam.com/video/RbT28X0wiRw/w-d-xo.html (just the part where we create the Google App Password for you email)

  • @bishalbanerjee8109
    @bishalbanerjee8109 3 ปีที่แล้ว

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

  • @youterisim6173
    @youterisim6173 3 ปีที่แล้ว

    Thank you so much !

  • @Digital_Life96
    @Digital_Life96 11 หลายเดือนก่อน

    From name is not working please help

  • @shivakumarpanaganti258
    @shivakumarpanaganti258 4 ปีที่แล้ว +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  4 ปีที่แล้ว +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.

  • @SparkFusionGames
    @SparkFusionGames 3 ปีที่แล้ว

    From where to get SMTP info?

    • @TonyTeachesTech
      @TonyTeachesTech  3 ปีที่แล้ว

      You can get that from you email provider

  • @mahmoudmostafa5259
    @mahmoudmostafa5259 4 ปีที่แล้ว

    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  4 ปีที่แล้ว +1

      Are you using Contact Form 7? There is a check box that you can see here th-cam.com/video/lif0tW2UWvw/w-d-xo.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 4 ปีที่แล้ว

      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  4 ปีที่แล้ว +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 4 ปีที่แล้ว

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

    • @TonyTeachesTech
      @TonyTeachesTech  4 ปีที่แล้ว

      @@mahmoudmostafa5259 I'm happy to hear that!

  • @rodrigoscustodio
    @rodrigoscustodio 4 ปีที่แล้ว

    Thank you!

  • @VSongu
    @VSongu 2 ปีที่แล้ว

    What does mean send an email from a website?

  • @jacksoncremean1664
    @jacksoncremean1664 2 ปีที่แล้ว

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

  • @Ryeburnyard
    @Ryeburnyard 2 ปีที่แล้ว

    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 6 หลายเดือนก่อน

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

  • @exi8965
    @exi8965 2 ปีที่แล้ว

    the fucking clickbait tho Jesus