Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Newsletter problem

Guest
Mar 18, 2010 Mar 18, 2010

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 = @mail( $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.

TOPICS
Server side applications
638
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 19, 2010 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 22, 2010 Mar 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";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 23, 2010 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 25, 2010 Mar 25, 2010
LATEST

was an issue with the headers. all sorted now. have also added a loop in that each call, i only send out 'n' number of emails and have a 'sent' field on the database so i know who it has been sent to.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines