1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Send an auto email every first day of month

Discussion in 'PHP' started by mirosoft1, Jun 8, 2018.

  1. #1
    Hello,
    I want to write PHP code to check the first day of every month like
    if(Y-M-01) but for every month and if true
    send an email to the client
    How can i do that?
    Thank you
     
    mirosoft1, Jun 8, 2018 IP
  2. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #2
    You could write PHP script that would send required email and run this script on the first day of month using cron job.
     
    Nei, Jun 8, 2018 IP
  3. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Thank you for your replay Nei but how i could do that?? i didn't use cron job before
    Can you please tell me how.
     
    mirosoft1, Jun 8, 2018 IP
  4. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #4
    Well, for example cron job usually is a part of Cpanel, or you could install cron job manually on your host, or you could ask support of your host to install cron.
     
    Nei, Jun 8, 2018 IP
  5. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    OK i got this part of cron job what is the next?
     
    mirosoft1, Jun 9, 2018 IP
  6. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #6
    Then you code the php-script that would send required email...or search similar script on the internet and make changes in it :)
     
    Nei, Jun 9, 2018 IP
  7. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #7
    About the code you asked,
    <?php
    if(date("d")==1){

    //send email
    mail( "", "subject", "this is email message", "From: noreply@your_domain.com" );

    }else{
    exit();
    }
    ?>

    Second, you'd need to automate it somehow, like suggested above, use cron
    In cron, if you set the script to run only on 1st of each month then you do not need condition check. Only your email script.

    <?php
    mail( "", "subject", "this is email message", "From: noreply@your_domain.com" );
    ?>
     
    JEET, Jun 14, 2018 IP
  8. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #8
    The answer is use a cronjob. The next thing for you to do is research cronjob to find out how to use it in your web hosting environment. It's silly to keep asking step by step questions. You're just killing time for yourself and taking up others...
     
    NetStar, Jul 8, 2018 IP