• 0

Email mailer php


Question

I am creating a mailer the issue I am having is that the header is separating the subject and body in to two emails. any help would be greatly appreciated.


<?php

if (isset($_POST))
	$postArray = &$_POST;
else
	$postArray = &$HTTP_POST_VARS;

	foreach ($postArray as $sForm => $value) {
	if (get_magic_quotes_gpc ())
 	$postedValue = ( $value );
	else
 	$postedValue = ( $value );
?>

<?php echo $sForm ?>



 $connection = @mysql_connect($host, $username, $password) or die("could not connect");
	$db = @mysql_select_db($dbname, $connection) or die("bd");
	$sql = "SELECT email FROM $T1";
	$res = @mysql_query($sql, $connection) or die("could not get address");
		$headers = "from \"your mailing lise\"\n";
	$headers = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";




	while ($row = mysql_fetch_array($res)) {

 	$email = $row['email'];
 	mail($email,$postedValue, $headers);
 	echo "newsletter sent to $email<br>";
	}
?>

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Without looking too deeply,

$headers = 'MIME-Version: 1.0' . "\r\n";

should be

$headers .= 'MIME-Version: 1.0' . "\r\n";

And mail function in php is in the following format

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

So your message is currently $headers...

Link to comment
Share on other sites

  • 0

As Sparky Marky said, it looks like you've got the parameters of the mail() function mixed up. The reason why 2 emails are being sent is because you have the mail function in a loop and by the sounds of things, your SQL query is returning more than 1 row for the same email address. Also, where do you set $postedValue?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.