Email using PHP

Discussion in 'PHP' started by eskimo87, Apr 28, 2010.

  1. #1
    Hi All,
    I have a website hosted at say, abc.com and I have database of registered users with their email id.
    Now I want to run a logic and get a subset of the users, and send them an email once a month. Something similar to reminder mail.
    As I see, this task is divided in three sub modules-
    1. A PHP script with a logic which will get me that subset of users

    2. A sendmail($email_id) kind of function which will do the work of sending mail to given address

    3. A way to schedule the execution of PHP script (of module#1) and sendmail function, so that email would be sent once in a month automatically


    I have module#1 ready but I am stuck with module #2 and #3.
    I am new to doing mail stuff using PHP, I want to know
    - what all things/settings I should be knowing to do send mail coding in PHP

    - I want to send all those reminder emails to users with admin@abc.com as sender , how to achieve that?

    - Any pointers to start off with this would be of great help


    When I search on how to go about implementing module#3, I found that CRON is preferred way to implement scheduling. But I enquired to my hosting provider and got to know that It is not accessible to me. So please let me know any other alternate ways to implement the scheduling of a PHP script.

    Thanks,
    Ravi
     
    eskimo87, Apr 28, 2010 IP
  2. Rory M

    Rory M Peon

    Messages:
    1,020
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why on earth wont they give you CRON Jobs? Err well short of triggering the script manually once per month, you could add a conditional statement to a regularly accessed page that runs the script if the date is the first day of the month and the script hasn't already been run in that day. That would obviously only work if there is some script within your main site that is used regularly.
     
    Rory M, Apr 28, 2010 IP
  3. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #3
    I'm quite surprised too that you can't setup cron scripts, I've never had an issue with that on shared hosting accounts before...? Unless you're on a Windows machine and it works differently?

    Anyway, email in PHP at it's simplest level can be sent like this:

    mail("user@email.com", "subject", "text content");
    PHP:
    You'd probably be better using a third party email class since it'll manage all the content, smtp config better. There's loads around, LibMail being a good one - http://lwest.free.fr/doc/php/lib/index.php3?page=mail&lang=en
     
    Last edited: Apr 29, 2010
    mfscripts, Apr 29, 2010 IP
  4. SunShellNET

    SunShellNET Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If cron isn't enabled on your account, you can either
    1. Signup with a free hosting provider who support cron and setup a cron using "wget" or "curl" so that the cron will call the file hosted on your main hosting provider
    or
    2. try running the script manually on every month

    As for sending the email, this simple function will be best


    You can also make use of advanced mail sending class such as PHPmailer for html format supprt
     
    SunShellNET, Apr 29, 2010 IP
  5. FriendSwapMeet.com

    FriendSwapMeet.com Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?php
    $to = "j@yahoo.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "admin";
    $headers = "From: $from";
    mail($to,$subject,$message,$headers);
    echo "Mail Sent.";
    ?>


    similar code with out having to use function.
     
    FriendSwapMeet.com, Apr 29, 2010 IP
  6. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #6
    As they said a cronjob on another server is the easiest way besides switching host. (i would do the last one)

    Anyway if you´re going to call it from another server, don´t forget to password protect it or anyone can trigger it at any time.
     
    n3r0x, Apr 30, 2010 IP
  7. Nakbali

    Nakbali Peon

    Messages:
    33
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i think this one work for me. thanks :)
     
    Nakbali, Apr 30, 2010 IP