Jump to content

[SOLVED] E-mail script


KingChaos

Recommended Posts

Hi.

 

I am currently using this script to send out e-mails.

 

<?



if($submit){
			// Check the form
			if ($subject=="") {
				echo "<html><body><script language=javascript1.1>alert('Please fill in the form'); javascript:history.back();</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
				exit;
			}
			$mail_count = "0";

			// Start email loop
			if($status == "supporters")
			{
			$result = mysql_query("SELECT * FROM `users` WHERE status = 'supporter' OR status = 'admin'");
			}
			if($status == "admin")
			{
			$result = mysql_query("SELECT * FROM `users` WHERE status = 'admin'");
			}

			elseif($status == "all")
			{
			$result = mysql_query("SELECT * FROM `users` WHERE status != 'banned'");
			}
			elseif($status == "normal")
			{
			$result = mysql_query("SELECT * FROM `users` WHERE status = 'normal' OR status = 'admin'");
			}
			while($r=mysql_fetch_array($result))
			{
				$mail_count++;


			$send_subject = "$sitename - $subject";
			$send_message = "$message\n\n\n This message was sent to you because you are a member of $sitename.";
				mail("$r[email]", "$send_subject", "$send_message", "From: $adminemail\r\nReply-To: $adminemail\r\n");
				echo "$mail_count -> $r[email]<br>";
			}
			// End loop

			echo "<html><body><script language=javascript1.1>alert('$mail_count Users Emailed'); window.location='index.php?pageid=mailall';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
			exit;
	}
?>
            <table class="table1" align="center" width="100%">
              <tr>
                <td class="tdrow2" colspan="2"><div align="center">
		<form name=form method=post action="">
		<table width=34% border=0>
		<tr>
		  <td width=15%> </td>
		  <td width=85%><u><b>Mass Mail Members</b></u><p></td>
		</tr>
		<tr>
		  <td width=11%>Subject:</td>
		  <td width=89%><input type=text name=subject size="60"></td>
		</tr>
		<tr>
		  <td>Message:</td>
		<td><textarea name=message rows=17 cols="46"></textarea></td>
		</tr>
	  	<tr>
              <td>Send To:</td>
	  	  <td>
		  	  <select size="1" name="status" id="status">
                  <option value="supporters">Supporters Only</option>
                  <option value="normal">Normal Members Only</option>
                  <option value="admin" selected="selected">Admins Only</option>

                  <option value="all">All Members</option>
                </select>              </td>
	  	  </tr>
		<tr>
		  <td> </td>
		  <td><input type=submit name=submit value=Send></td>
		</tr>
	  </table>
	  </form>
		  </td>
		  </tr>
            </table>

 

It is working just fine as an text-only "newsletter".

It gets mail addresses from a database based on member status from a dropdownbox.

 

Now I need to change this script to one of the following:

 

1. Insert header and footer from file.

 

2. Use a templete system.

 

3. Using Tables.

 

 

 

Any sugestions? PS: I need the mysql_query thats already in the script.

Any easy way to just change a few lines in the script to make it send out the mail in html format?

 

 

King

 

Link to comment
https://forums.phpfreaks.com/topic/63224-solved-e-mail-script/
Share on other sites

Ok.. Been fooling around some more, and found out that I neede to use $headers, MIME and Content-type.

 

So I inserted this into my script:

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

 

 

But all I get in my e-mailis exactly what is written. This is my recived mail.

 

<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>

 

What am I doing wrong?  ???

 

King

Link to comment
https://forums.phpfreaks.com/topic/63224-solved-e-mail-script/#findComment-315728
Share on other sites

Finaly figured it out. Here is my final script. If someone may need it, it fetch e-mail adresses from a mysql db.

 

 

<?



if($submit){







			// Check the form
		if ($subject=="" OR $message_body=="") {
				echo "<html><body><script language=javascript1.1>alert('Please fill in the form'); javascript:history.back();</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
				exit;
			}
			$mail_count = "0";

			// Start email loop
			if($status == "supporters")
			{
			$result = mysql_query("SELECT * FROM `users` WHERE status = 'supporter' OR status = 'admin'");
			}
			if($status == "admin")
			{
			$result = mysql_query("SELECT * FROM `users` WHERE status = 'admin'");
			}

			elseif($status == "all")
			{
			$result = mysql_query("SELECT * FROM `users` WHERE status != 'banned'");
			}
			elseif($status == "normal")
			{
			$result = mysql_query("SELECT * FROM `users` WHERE status = 'normal' OR status = 'admin'");
			}
			while($r=mysql_fetch_array($result))
			{
				$mail_count++;






			$headers = "From: $adminemail\r\nReply-To: $adminemail\r\n";
			$headers.= "Content-Type: text/html; ";
			$headers .= "MIME-Version: 1.0 ";
			$message_header = "

<P><here goes your html codes for the header.>
";

			$message_footer = "

<p><here goes your html codes for the footer.>
";





			$send_subject = "$sitename - $subject";
			$send_message = "$message_header<p>$message_body<p>$message_footer";

mail("$r[email]", "$send_subject", "$send_message", "$headers");
				echo "$mail_count -> $r[email]<br>";
			}
			// End loop

			echo "<html><body><script language=javascript1.1>alert('$mail_count Users Emailed'); window.location='index.php?pageid=htmlmail';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
			exit;
	}





?>
      <table class="table1" align="center" width="100%">
              <tr>
                <td class="tdrow2" colspan="2"><div align="center">
		<form name=form method=post action="">
		<table width=34% border=0>
		<tr>
		  <td width=15%> </td>
		  <td width=85%><u><b>Mail Members</b></u><p></td>
		</tr>
		<tr>
		  <td width=11%>Subject:</td>
		  <td width=89%><input type=text name=subject size="60"></td>
		</tr>
		<tr>
		<td>Message body:</td>

		<td><textarea name=message_body rows=17 cols="50">Here goes your message body</textarea></td>
		</tr>
	  	 <tr>
              <td>Send To:</td>
	  	  <td>
		  	  <select size="1" name="status" id="status">
                  <option value="supporters">Supporters Only</option>
                  <option value="normal">Normal Members Only</option>
                  <option value="admin" selected="selected">Admins Only</option>

                  <option value="all">All Members</option>
                </select>              </td>
	  	  </tr>
		<tr>
		  <td> </td>
		  <td><input type=submit name=submit value=Send></td>
		</tr>
	  </table>
	  </form>
		  </td>
		  </tr>
            </table>

 

 

King

Link to comment
https://forums.phpfreaks.com/topic/63224-solved-e-mail-script/#findComment-316074
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.