Skip to main content
March 18, 2010
Question

Newsletter problem

  • March 18, 2010
  • 1 reply
  • 638 views

Hi,

I have created a PHP script to send out a newsletter to a single email address. Format is spot on on recipient email account. What I want to do now is for every email address in a table, I want to send the newsletter to them all, but its only sending out 1 and then nothing else.

Here is my table:

Table name : test

Fields:          email varchar2(20)

main php script (test version)

<html>
<title>email test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="./../Style/Format.css" rel="stylesheet" type="text/css">
</head>
<body class="body" bgcolor="#FFFFFF" text="#000000" topmargin="2">
<?php
$month='March';
$year='2010';
$date_start='2010-03-01';
$date_finish='2010-03-31';
?>
<div align="center">
  <?php include("db.php"); ?>   
  <br>
<?php
$result1 = mysql_query("SELECT * FROM test")
or die(mysql_error());
while($row1 = mysql_fetch_array( $result1 ))
{
include("./email_test.php");
}
?>
</body>
</html>

email_test.php

<?php
$to = $row1['email'];
$subject = $month.' '.$year.' Newsletter';
$random_hash = md5(date('r', time()));
$headers = "MIME-Version: 1.0\n";
$headers .= "From: test@test.Com>\r\nReply-To: test@test.com";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
ob_start();
?>
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="utf8"
Content-Transfer-Encoding: 7bit
<div align="center">Having trouble viewing this email? <a href="http://www.test.com/<?php echo $month.$year.".php";?>">Web Version</a></div><br><br>

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="utf8"
Content-Transfer-Encoding: 7bit

<?php

$result3 = mysql_query("xxxxxxx")
or die(mysql_error());
while($row3 = mysql_fetch_array( $result3 ))
{
include("./news_boxes.php");    
}
?>

--PHP-alt-<?php echo $random_hash; ?>--
<?
$message = ob_get_clean();
$mail_sent = @644699( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

Like i said, i get one email received (1st record), there are 5 test records in my table. Am I missing something as im sure im looping around the table?

Thanks.

This topic has been closed for replies.

1 reply

March 19, 2010

i've stuck a counter in the loop also, but it only gets to 1, so for sure, its

only getting into the 1st loop and the exiting the loop.

is this a limitation of using 'mail'? any suggestions appraciated.

March 22, 2010

Found this example on the 'net, will give this a go later on:

$mail_to_name = 'one@home.com,two@home.com';
$rec = 'me@mine.com';
$subj = 'Lost keys"';
$msg = 'Hi friends, I lost my keys, anyone seen them? Please mail me back. /Thanks';

$headers = "From: Myself <me@mine.com>\n";
$headers .= "X-Mailer: PHP\n";
$headers .= "X-Priority: 1\n"; // Urgency!
$headers .= "Return-Path:<me@mine.com>\n";
$headers .= "bcc:$mail_to_name\n";

March 23, 2010

I have got past the email problem in that i have created a string like:

'a@a.com, b@b.com, c@c.com' and it has been sent out fine.

But, yahoo email accounts receive the html newsletter email, but its blank. is there a way past this? i have tested hotmail, excite and google and they are all fine.

thanks.