Jump to content

Email Script


Hooch

Recommended Posts

Hello all.I created a script to send emails that worked great originally.I had the option to send an email to 1 or all members on the site.The members emails were hidden via Bcc.Now since the owner wants the emails to be shown in the "To" field(not Bcc) the code does not send the emails.(Just an FYI I swapped the $to variable (that has many emails)with 5 emails and it worked.)Before I post any code is there a problem when the "To" field hasa lot of emails in it?Thanks for any info.

Link to comment
Share on other sites

I just tried converting back to the Bcc and there's still an error.So it's my code.

<?PHPsession_start(); if(isset($_SESSION['username']) && ($_SESSION['level'] >= 1)) {	//Set session for all the emails	$all_emails = implode(";", $_POST['id']);	$set_emails = str_replace(";", ",", $all_emails);		$_SESSION['all_emails'] = $set_emails;	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';	echo '<html xmlns="http://www.w3.org/1999/xhtml">';			echo '<head>';	echo '<title>Emails</title>';	echo '<link href="../includes/style.css" rel="stylesheet" type="text/css" />'; 	echo '<script type="text/javascript" src="http://mysite.org/js/chromejs/chrome.js"></script>';	echo '</head>';			//Include some navigation	include '../links_cpanel.php';	//Show Form (two columns here)	echo '<tr>';	echo '<td align="left" valign="top">';	if($_POST['submit'])	{		$file_name = trim($HTTP_POST_FILES['ufile']['name']);		$file_name = str_replace (" ", "", $file_name);		$ufile	 = trim($_POST['ufile']);		//=======================Upload part=======================\\		$_SESSION['all_emails'] = $_POST['all_emails'];		$path = "../files/emails/" . str_replace(" ", "", $HTTP_POST_FILES['ufile']['name']);		if(strlen($file_name) >= 3)		{			if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))			{				include '../includes/db.php';				$file_name = trim($HTTP_POST_FILES['ufile']['name']);				$file_name = str_replace(' ', '', $file_name);				$file_size = $HTTP_POST_FILES['ufile']['size'];				$file_type = $HTTP_POST_FILES['ufile']['type'];				$file_date = time();				$member	= $_SESSION['user_firstname']." ".$_SESSION['user_lastname'];				$query	 = mysql_query("INSERT INTO `email_files` (`id`, `file_name`, `member`, `file_date`) VALUES ('', '$file_name', '$member', '$file_date')")or die(mysql_error());						$_SESSION['file_name'] = $file_name;				}					else				{					echo "<br /><center><strong class=\"error_text\">There was an error while uploading your file.</strong><br /><br /></center>";					exit();				}			}				//send the email		//Set up info 				$file_name = $_SESSION['file_name'];   		$to		= 'me@mysite.org';		$subject   = stripslashes($_POST['txtSubject']);		$headers   = "From: <".$to.">\r\n";		$headers  .= "Return-Path: <".$to.">\r\n";		$headers  .= 'MIME-Version: 1.0' . "\r\n";		$headers  .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";		//$headers  .= '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />' . "\r\n";		$headers  .= "Bcc:".$_SESSION['all_emails']."\r\n";			$message   = stripslashes(nl2br($_POST['txtMessage']));		$message  .= "<br />";								if(strlen($file_name) <= 3)		{			echo '';		}			else		{			$message .= '<br />';			$message .= '<a href="http://www.mysite.org/email_file.php?file='.$file_name.'" style=\"text-decoration:underline;color:#0000FF;font-family:Verdana;font-size:15px;font-weight:bold\">download/view</a>';			$message .= '<br /><br />';		}						if(mail($to, $subject, $message, $headers))		{			//Was there a file uploaded?			//Show nothing if not, otherwise let them know it was uploaded			if(strlen($file_name) <= 3)			{				echo '';			}				else			{				echo "<strong class=\"error_text_green\">".$file_name." has been uploaded.</strong><br />";			}			//Unset session			$_SESSION['s_tours'] = '';			echo "<strong class=\"error_text_green\">Transferring to your CPanel.<br />";			echo '<meta http-equiv="Refresh" content="3; URL=../cpanel.php?id=' .$_SESSION['user_id'] . '"/>';				exit();		}			else		{			echo '<strong class="error_text">Mail not sent</strong><br /><br />';			exit();		}			}?>	<!-- File Upload -->	<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">	<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />	<input type="hidden" name="all_emails" value="<?PHP echo $_SESSION['all_emails']; ?>">	Upload a file?:<span class="error_text_green">(3MB Max)<br />	<input name="ufile" type="file" id="ufile" size="30" value="--"/><br />	<b>From:</b> <?PHP echo $_SESSION['email'];?><br />	<!-- Add text to email -->	<b>Subject:</b><br />	<input name="txtSubject" type="text" class="txtbox" title="" size="55" maxlength="54" />	<br />	<b>Message:</b><br />	<textarea name="txtMessage" cols="51" rows="10" wrap="VIRTUAL" class="txtbox" /></textarea><br />	<input name="Reset" type="reset" value="Clear"/> <input name="submit" type="submit" value="Send" />	</form><?PHP		echo '</td>';		echo '<td align="left" valign="top" class="grey-10"> ';		echo '</td>';		echo '</tr>';		echo '</table>';//Show an error since they are not logged in or not an Admin	} 	else{		echo "<link href=\"../includes/style.css\" rel=\"stylesheet\" type=\"text/css\" />";	echo("<center><p> </p><p> </p><p> </p>Sorry, but you are not allowed to view this page!<br />");	echo("Please log in to view<br />"); 	echo("<br><a href=\"../index.php\" target\"_self\" class=\"link_grey_13_underlined\">BACK</a></center>");}?>

Link to comment
Share on other sites

The email come from a javascript code. I use it to select all or unselect.So the user needs to check a box for an email to be sent.

<?PHP session_start(); ?>	<!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=iso-8859-1" />	<title>Member Emails</title>	<link href="../includes/style.css" rel="stylesheet" type="text/css" />		<script type="text/javascript" src="http://mysite.org/js/chromejs/chrome.js"></script>		<script language = "Javascript">		<!-- 		/**		 * DHTML check all/clear all links script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)		 **/				var form='emails' //Give the form name here				function SetChecked(val,chkName) {		dml=document.forms[form];		len = dml.elements.length;		var i=0;		for( i=0; i<len; i++) {		if (dml.elements[i].name==chkName) {		dml.elements[i].checked=val;		}		}		}				function ValidateForm(dml,chkName){		len = dml.elements.length;		var i=0;		for( i=0; i<len; i++) {		if ((dml.elements[i].name==chkName) && (dml.elements[i].checked==1)) return true		}		alert("Please select at least one client")		return false;		}		// -->		</script>	</head>	<?PHP	//Do a query for the members info	include '../includes/db.php';		//Include some navigation	include '../links_cpanel.php';		//Welcome message	echo '<tr>';	echo '<td height="40" background="../images/admin_nav_background.gif" >  Welcome '.$_SESSION['username'].' to our Member Emails page.</td>';	echo '</tr>';	echo '<tr>';	echo '<td align="left" valign="bottom">';		include'email_links.php';	echo '</td>';	echo '</tr>';	echo '<tr>';	echo '<td align="left">';	//-----------------------------------------	   Dynamic Columns		-----------------------------------------//	$query = "SELECT COUNT(*) as num FROM `users` WHERE `active` = 1";	$total = mysql_fetch_array(mysql_query($query));	$total = $total['num'];	if ($total <=15)	{		$rows = 1;	}		elseif ($total >= 16 && $total <= 30)	{		$rows = 2;	} 		elseif ($total >= 31 && $total <=45)	{		$rows = 3;	}		elseif ($total >= 46)	{		$rows = 4;	}			define('NUM_COLS', $rows); 	//Show results 			$query = "SELECT * FROM `users` WHERE `active` = 1 ORDER BY `lastname` ASC"; 		$result = @mysql_query($query) or die(mysql_error()); 		$cats = array(); 		while($cat=mysql_fetch_array($result)) 		{ 			array_push($cats, $cat); 		} 			$catsCnt = count($cats); 		echo "<table border='0' cellpadding='2' cellspacing='2' width='700' align='center'>"; 		echo "<tr>"; 		for($x=0; $x < $catsCnt; $x++) 		{ 			if(($x+1) % NUM_COLS == 0) 			{ 				echo "<td width='".(100/NUM_COLS)."%' NOWRAP>";							//Check if the user from the DB has an email set, if not distinguish differently				if($cats[$x]['email'] == "")				{					echo '<div class="pagination_left"><span class="current">' . $cats[$x]['firstname'] . ' ' . $cats[$x]['lastname'] . '</span></div>';				}					else				{					echo ' <input type="checkbox" name="id[]" value="' . $cats[$x]['email'] . '" checked="checked">' . $cats[$x]['firstname'] . ' ' . $cats[$x]['lastname'] . ' ';				}							echo "</td></tr>"; 			if ($x!=($catsCnt-1)) echo "<tr>"; 			} 				else 			{ 				echo "				<td width='".(100/NUM_COLS)."%' NOWRAP >";				//Check if the user from the DB has an email set, if not distinguish differently				if($cats[$x]['email'] == "")				{					echo '<div class="pagination_left"><span class="current">' . $cats[$x]['firstname'] . ' ' . $cats[$x]['lastname'] . '</span></div>';				}					else				{					echo ' <input type="checkbox" name="id[]" value="' . $cats[$x]['email'] . '" checked="checked">' . $cats[$x]['firstname'] . ' ' . $cats[$x]['lastname'] . ' ';				}								echo "</td>"; 			} 		} 		$numSpaces=$catsCnt%NUM_COLS; 		if ($numSpaces!=0) 		{ 			for ($i=0;$i<=$numSpaces;$i++) 			{ 				echo "<td width='".(100/NUM_COLS)."%' NOWRAP> </td>"; 			} 		echo "</tr>";		echo '</table>'; 		} 	//---------------------------------------	   End Dynamic Columns		---------------------------------------//	echo '</td>';	echo '</tr>';	echo '<tr>';	echo '<td height="40" colspan="10" background="../images/admin_nav_background.gif" >  </td>';	echo '</tr>';	echo '</table>';?>

Link to comment
Share on other sites

  • 2 weeks later...

Archived

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

×
×
  • Create New...