Skip to content

Instantly share code, notes, and snippets.

@amkaos
Last active December 16, 2015 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save amkaos/5357240 to your computer and use it in GitHub Desktop.
Save amkaos/5357240 to your computer and use it in GitHub Desktop.
<?php
// named connect.php
// usable constants
define('DB_NAME', 'nameOfDatabase');
define('DB_USER', 'UserName');
define('DB_PASSWORD', 'UserPassword');
define('DB_HOST', 'localhost');
$connect = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
if(!$connect) {
die('Could not connect: ' .mysql_error());
}
$db_selected = mysql_select_db(DB_NAME,$connect);
if(!$db_selected) {
die('Can\'t use' . DB_NAME . ':' .mysql_error());
}
echo 'Connected successfully';
?>
// I GET THE "CONNECTED SUCCESSFULLY" ECHO ON PAGE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
// This is called index.php
<?php
require('connect.php');
echo"<h1>Mailing List</h1>Send To<p>";
// setup variable
$mailcount = 0;
$namecount = 0;
$get = mysql_query("SELECT * from admin_table");
echo "<form action='send.php' method='GET'>";
while ($getrow = mysql_fetch_assoc($get))
{
echo "<input type = 'checkbox' name = 'mail_ ".$mailcount++." ' value
= '".$getrow ['email'] ."' CHECKED >
".$getrow['fullname'] . " (".$getrow['email'].")
<input type = 'hidden' name='name_ ".$namecount++."' value =
'".$getrow ['fullname'] ."'>
<br> ";
}
echo "<p> Message: <br><textarea name = 'message' ></textarea> <p>
<input type = 'submit' name = 'submit' value = 'Send' >
</form>";
?>
// This works just as it should (list of names and emails from database)and
// after i hit 'Submit' i get 'Connected successfully All Mail Has Been
Processed'
// but no emails are sent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
// This is the 'send.php'
<?php
require('connect.php');
// change php.ini smtp line
//ini_set( "mail.tap.com"); i am using an actual host and this line is for
xaamp
// i did try leaving the line uncommented but it did not make any difference
// standard mail header
$headers = "From: tap.com";
// get meessage to send
$message = $_GET['message'];
// loop through names / emails on index form
for ($x=0; $x<count($_GET); $x++)
{
if ($_GET["mail_$x"])
{
// mail setup
$to = $_GET["mail_$x"];
$subject = "News From Tap ";
$body = "Dear " . $_GET["name_$x"] . "
\n\n $message \n\n Josh \n\n Tap ";
mail($to, $subject, $body, $headers );
}
}
echo "All Mail Has Been Processed";
?>
// after i hit 'Submit' i get 'Connected successfully All Mail Has Been
Processed'
//// but no emails are sent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment