Jump to content

Php Mysql and Gmail Help


peterengland

Recommended Posts

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

Edited by peterengland
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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