Jump to content

peterengland

New Members
  • Posts

    2
  • Joined

  • Last visited

peterengland's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello I have a mysql database with filds like Name , DEPT ,and DOB the table name is emp and database name is EMPMASTER i have pear mail working script using gmail smtp and a Mysql query that shows todays birthday , My question is how to mix these two codes to mail output of that Mysql query in mail ? please suggest. following is the php code and my sql query. <?php // Pear Mail Library require_once "Mail.php"; $from = '<user@user.com>'; $to = '<user@user.com>'; $subject = 'Hi!'; $body = "Hi,\n\nHow are you?"; $headers = array( 'From' => $from, 'To' => $to, 'Subject' => $subject ); $smtp = Mail::factory('smtp', array( 'host' => 'ssl://smtp.gmail.com', 'port' => '465', 'auth' => true, 'username' => 'user@gmail.com', 'password' => '123@123' )); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo('<p>' . $mail->getMessage() . '</p>'); } else { echo('<p>Message successfully sent!</p>'); } ?> SELECT * FROM emp WHERE MONTH(dob) = MONTH(NOW()) AND DAY(dob) = DAY(NOW());
  2. Hi, I need a php script that connect to a mysql database and retrive the current date birthday information and mail through php mail using gmail smtp to about 1500 mail addresses. I have database ready with me name of database in empmaster like Firstname lastname Date of Birth and this php page is going to run everyday and mail if there is birthday today of anyone. Thanks in Advance please help someone. I have one example (not exactly related to my requirement but for only example i tried it but not worked with exammp) found from Internet pls see in attachment. ----------------------------------------------code------------------------------------------------------------------ <?php require_once('connect/test.php'); ?> //This makes the connection to mysql database <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Home Page</title> </head> <body> <h3>Thank you!</h3> <p> <?php require_once("phpMailer/lib/class.phpmailer.php"); require_once("phpMailer/lib/class.smtp.php"); require_once("phpMailer/lib/language/phpmailer.lang-en.php"); $to_name = "sammuel"; $to = "gfgdfgh@gmail.com"; $subject = "A new user has been registered to the website"; $from_name = "John Smith"; $from = "ggffdhfg@gmail.com"; //PHP SMTP version $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp.gmail.com"; $mail->Port =587; $mail->SMTPAuth = false; $mail->Username = "gffdhgdhhhd@dgs.com"; $mail->Password = "password"; $mail->FromName = $from_name; $mail->From = $from; $mail->AddAddress($to, $to_name); $mail->AddAddress("gdhdhdhh@gmail.com"); $mail->IsHTML(true); $mail->Body = "<html><head></head><body><h2>A new user has registered at my website</h2>"; // ======== get database data ================== $link = mysqli_connect("localhost","root","12345"); $database="mydatabase"; mysqli_select_db ($database,$link) OR die ("Could not open $database" ); $query = "SELECT * FROM A WHERE id= 123"; //xyz is id of desired user name. $result1 = mysqli_query($query); // error checking may be required here while ($a_row = mysqli_fetch_array($result1) $mail->Body .= "<p>Name: ". $a_row['name'] . "</p>"; $mail->Body .= "<p>Surname: ". $a_row['surname'] . "</p>"; $mail->Body .= "<p>Email: " . $a_row['email'] . "</p>"; $mail->Body .="</body></html>"; // not sure how $mail-->Body in OOP but that is the general idea from a procedure guy. // etc.... } // end database code $result = $mail->Send(); echo $result ? 'Thanks for your registering... Your information has been recorded in our database.' : 'Error'; ?> </body> </html> ---------------------------------------------------end of code--------------------------------------------------------------
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.