Member Avatar

Hi everyone. I have made a mailing list script but I want to modify it so that I can post some variables in the message box.

I would like something like this.

To display something like this.


I have tried putting

' . $fetch['first'] . '


and

$fetch['first']


in the message box put it just prints out what i have typed.

Please could I get some help because this is really annoying me.

Thanks in advance.

Recommended Answers

I think we'll need to see more of the code.

Jump to Post

THis isn't a solution, but how about separating your php and html. Mixing them like this makes for messy code. I'd place all data into variables and then echo out the variables in the appropriate place. That should tidy up things.

Jump to Post

All 7 Replies

I think we'll need to see more of the code.

Member Avatar

mailing_list.php

<form name="mailing_list" action="mailing_list_send.php" method="post">

			 	<table>

                	<thead>

                        <tr>

                            <th width="15%">Send To</th>

                            <th>:</th>

                            <th>
							<?php
							$mailcount = 0;
							$namecount = 0;
							$get = mysql_query("SELECT * FROM users WHERE adminemails='1'");
							while($getrow = mysql_fetch_assoc($get))
							{
								echo '<input type="checkbox" name="mail_' . $mailcount++ . '" value="' . $getrow['email'] . '" checked /> ' . $getrow['username'] . ' (' . $getrow['email'] . ')<br />';
   echo '<input type="hidden" name="name_' . $namecount++ . '" value="' . $getrow['username'] . '" />';
							}
							?>
                            </th>

                        </tr>

                        <tr>

                            <th width="15%">Subject</th>

                            <th>:</th>

                            <th><input type="text" name="subject" id="subject" class="text-input" /></th>

                        </tr>

                        </thead>

                        </table>

                        <table>

                        <thead>

                        <tr>

                            <th>

                            Message

                            <textarea rows="6" name="messageuser" id="messageuser"></textarea>

                            </th>

                        </tr>

                        <tr>

                            <th width="15%"><input type="submit" name="send" value="Send" class="button" /></th>

                            <th>&nbsp;</th>

                            <th>&nbsp;</th>

                        </tr>

                    </thead>

                </table>

                </form>

mailing_list_send.php

<?php
require '../connect.php';

if(isset($_POST['send']))
{

for($x=0;$x<$_POST;$x++)
{
  if ($_POST['mail_' . $x . ''])
  {
		$to = $_POST['mail_' . $x . ''];
		
		$subject = $_POST['subject'];
		
		$message = $_POST['messageuser'];
		
		$body = '
		<html>
		<head>
		<style type="text/css">
		body {
		font-family: Arial, Helvetica, sans-serif;
		font-size: 16px;
		}	
		
		.bold {
		font-weight: bold;
		}
		</style>
		<title>' . $subject . '</title>
		</head>
		
		<body>
		' . $message . '
		</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";
		
		// More headers
		$headers .= 'From: Mega Instrumentals <notifications@megainstrumentals.co.uk>' . "\r\n";
		
		$mail = mail($to, $subject, $body, $headers);
		
		if($mail)
		{
			header('location: mailing_list.php?send=1');
		}
		else
		if(!$mail)
		{
			header('location: mailing_list.php?send=0');
		}
  }
}
}
?>
Member Avatar

Can anyone help?

Member Avatar

THis isn't a solution, but how about separating your php and html. Mixing them like this makes for messy code. I'd place all data into variables and then echo out the variables in the appropriate place. That should tidy up things.

Member Avatar

Can anyone help me with the code please?

Can you explain where your actual problem is? And we can help you out accordingly. Because what you are actually doing there is saying that you want something but we do not know your problem.

Member Avatar

I am trying to make an email form where my admins and staff can email multiple users and they can type something like %username% and it will display the username of the user. I have tried $fetch but it just prints that out in the email.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.