phpcodelearner
03-06-2010, 08:49 PM
hi
i am tring to to a page where the admin can send a email to all of his users.
But first of all i am using tinymce editor (as it is the best one i know of) to design the message so the email has script has to know i am using html and i want to submit the newsletter to a table in my daterbase so i can look at pass newsletters.
i have managed that but i am stuck with how to call all my users email adress back from the daterbase called mywigan and table called user under the coloum called email.
now at the moment i have this
<?php require_once('../../Connections/mywigan.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO newsletter (`from`, subject, body) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['from'], "text"),
GetSQLValueString($_POST['subject'], "text"),
GetSQLValueString($_POST['body'], "text"));
mysql_select_db($database_mywigan, $mywigan);
$Result1 = mysql_query($insertSQL, $mywigan) or die(mysql_error());
}
?>
<script type="text/javascript" src="../../jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime ,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualcha rs,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,just ifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|, undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,b ackcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,| ,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,vis ualchars,nonbreaking,template,pagebreak,restoredraft",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
content_css : "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
// Style formats
style_formats : [
{title : 'Bold text', inline : 'b'},
{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
{title : 'Example 1', inline : 'span', classes : 'example1'},
{title : 'Example 2', inline : 'span', classes : 'example2'},
{title : 'Table styles'},
{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
],
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">From:</td>
<td><input type="text" name="from" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Subject:</td>
<td><input type="text" name="subject" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">message:</td>
<td><textarea name="body" cols="50" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="send" onsubmit="<?php ++$send ;?>"> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p>
<?php
// multiple recipients
if (!empty($_POST['subject'])){
$to = 'email@adress.com'; /*HELP this is where i did to get all the email from the dater base*/
// subject
$subject = $_POST['subject'];
// message
$message = $_POST['body'];
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: sammottley@foo.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
} else {
echo '';
};
?>
</p>
near the botom it says this :-
$to = 'email@adress.com'; /*HELP this is where i need to get all the email from the dater base*/
and this is the line i need help on i don't know how to call all my email adress back from the daterbase and set them under the variable of $to.:(
can you help me please?
If there is a better way of doing this or some better code that i can use please tell me :)
thanks alot :thumbsup:
i am tring to to a page where the admin can send a email to all of his users.
But first of all i am using tinymce editor (as it is the best one i know of) to design the message so the email has script has to know i am using html and i want to submit the newsletter to a table in my daterbase so i can look at pass newsletters.
i have managed that but i am stuck with how to call all my users email adress back from the daterbase called mywigan and table called user under the coloum called email.
now at the moment i have this
<?php require_once('../../Connections/mywigan.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO newsletter (`from`, subject, body) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['from'], "text"),
GetSQLValueString($_POST['subject'], "text"),
GetSQLValueString($_POST['body'], "text"));
mysql_select_db($database_mywigan, $mywigan);
$Result1 = mysql_query($insertSQL, $mywigan) or die(mysql_error());
}
?>
<script type="text/javascript" src="../../jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime ,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualcha rs,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,just ifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|, undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,b ackcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,| ,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,vis ualchars,nonbreaking,template,pagebreak,restoredraft",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
content_css : "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
// Style formats
style_formats : [
{title : 'Bold text', inline : 'b'},
{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
{title : 'Example 1', inline : 'span', classes : 'example1'},
{title : 'Example 2', inline : 'span', classes : 'example2'},
{title : 'Table styles'},
{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
],
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">From:</td>
<td><input type="text" name="from" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Subject:</td>
<td><input type="text" name="subject" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top">message:</td>
<td><textarea name="body" cols="50" rows="5"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="send" onsubmit="<?php ++$send ;?>"> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p>
<?php
// multiple recipients
if (!empty($_POST['subject'])){
$to = 'email@adress.com'; /*HELP this is where i did to get all the email from the dater base*/
// subject
$subject = $_POST['subject'];
// message
$message = $_POST['body'];
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: sammottley@foo.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
} else {
echo '';
};
?>
</p>
near the botom it says this :-
$to = 'email@adress.com'; /*HELP this is where i need to get all the email from the dater base*/
and this is the line i need help on i don't know how to call all my email adress back from the daterbase and set them under the variable of $to.:(
can you help me please?
If there is a better way of doing this or some better code that i can use please tell me :)
thanks alot :thumbsup: