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 = "[email protected]";
$subject = "A new user has been registered to the website";
$from_name = "John Smith";
$from = "[email protected]";

//PHP SMTP version
$mail = new PHPMailer();

$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port =587;
$mail->SMTPAuth = false;
$mail->Username = "[email protected]";
$mail->Password = "password";

$mail->FromName = $from_name;
$mail->From = $from;
$mail->AddAddress($to, $to_name);
$mail->AddAddress("[email protected]");
$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--------------------------------------------------------------

Link to comment
https://forums.phpfreaks.com/topic/281083-php-mysql-and-gmail-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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