Hello,
I'm new on daniweb, and it's my first post (to start sorry for any language mistake, my language is french).

Well, I'm developping a website for a client in php, the theme of the website is that registred users can make online consultations with a doctor, in the registration page the user has to add birth date of his child (cauz the consultation is for childs only), now if the child has 3 or 4 years for exemple an e-mail will be sent to his parent to remind him that his son has to do BCG vaccination for exemple.

Any Idea or script about this?

Thank you very much

Bonjour,

here is a PHP script that I use that allows you to attach a file to the email. Therefore is you develop an appointment card or vaccination card then this is perfect for it.

$to = "Patient name."<".$emailaddress.">";
       $subject = "vaccinations";
        $from = "The Doctor <bookings@thedoctors.com>";  
    
        $fileatt = "localdirectory/";
		$fileatt .= $filename;
        $fileatttype = "application/pdf"; 
		$fileattname .= $filename;
    
        $headers = "From: $from";
        $file = fopen( $fileatt, 'rb' ); 
        $data = fread( $file, filesize( $fileatt ) ); 
        fclose( $file );


        $semi_rand = md5( time() ); 
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    
        $headers .= "\nMIME-Version: 1.0\n" . 
                    "Content-Type: multipart/mixed;\n" . 
                    " boundary=\"{$mime_boundary}\"";
    
        $message = "This is a multi-part message in MIME format.\n\n" . 
                "--{$mime_boundary}\n" . 
                "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
                "Content-Transfer-Encoding: 7bit\n\n" . 
                $messageletter . "\n\n";
    
        $data = chunk_split( base64_encode( $data ) );
                 
        $message .= "--{$mime_boundary}\n" . 
                 "Content-Type: {$fileatttype};\n" . 
                 " name=\"{$fileattname}\"\n" . 
                 "Content-Disposition: attachment;\n" . 
                 " filename=\"{$fileattname}\"\n" . 
                 "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                 "--{$mime_boundary}--\n";

        if( mail( $to, $subject, $message, $headers ) ) {
         
            echo "<p>The email was sent.</p>"; 
         
        }
        else { 
        
            echo "<p>There was an error sending the mail.</p>"; 
         
        }

you would trigger this code once the person has submitted their details.

Any questions email me.

Noel.

Thank you NOEL, but I want something wich is cron (Automatic), when the child reaches 3 years an e-mail will be sent. the date is stored in database, the script will run once a day to check the age when reach 3 years old, for exemple, an e-mail will be sent to his parent.

I hope you undertood me;

Thank you

ok

1. Create a PHP file email.php

mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable"); <- change the SQL so that it selects all the records from your own database. I do not know the table or field names but you will know what you are doing here.

while ($row = mysql_fetch_array($result, MYSQL_BOTH)) 
{

        $to = "Patient name."<".$row["emailaddress"].">";
       $subject = "vaccinations";
        $from = "The Doctor <bookings@thedoctors.com>"; 
        $message = "your child needs a BCG injection"; <- insert your own message here this is what appears in the email body.

        $fileatt = "localdirectory/";
		$fileatt .= $filename;
        $fileatttype = "application/pdf"; 
		$fileattname .= $filename;
    
        $headers = "From: $from";
        $file = fopen( $fileatt, 'rb' ); 
        $data = fread( $file, filesize( $fileatt ) ); 
        fclose( $file );


        $semi_rand = md5( time() ); 
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    
        $headers .= "\nMIME-Version: 1.0\n" . 
                    "Content-Type: multipart/mixed;\n" . 
                    " boundary=\"{$mime_boundary}\"";
    
        $message = "This is a multi-part message in MIME format.\n\n" . 
                "--{$mime_boundary}\n" . 
                "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
                "Content-Transfer-Encoding: 7bit\n\n" . 
                $messageletter . "\n\n";
    
        $data = chunk_split( base64_encode( $data ) );
                 
        $message .= "--{$mime_boundary}\n" . 
                 "Content-Type: {$fileatttype};\n" . 
                 " name=\"{$fileattname}\"\n" . 
                 "Content-Disposition: attachment;\n" . 
                 " filename=\"{$fileattname}\"\n" . 
                 "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                 "--{$mime_boundary}--\n";

        if( mail( $to, $subject, $message, $headers ) ) {

         you would write this part to a log file incase you wanted to check which emails had been sent

            echo "<p>The email was sent.</p>"; 
         
        }
        else { 
        
            echo "<p>There was an error sending the mail.</p>"; 
         
        }
}

2. Set up the cron job

If your PHP is installed using the Apache module. First, you need access to Lynx. Lynx is a small web browser, generally available on Unix and Linux.

Running your PHP script will not require you to add any additional lines. You simply have to edit your /etc/crontab file and add the following line:

* * * * * lynx -dump http://www.yoursite.com/email.php

from the command line type

Shell> crontab crontab

There you go all done. It is never as simple as it looks but once you have set everything up the way you want it then it will all work fine.

Any questions give me a shout.

This article has been dead for over six months. Start a new discussion instead.