//test all mail table -- and tables tegether $body=$tb;
/* Create a new Net_SMTP object. */ if (! ($smtp = new Net_SMTP($host))) { /*without $host, mail still can be sended but it need to wait a few minuts. */ die("Unable to instantiate Net_SMTP object\n"); } /* Connect to the SMTP server. */ if (PEAR::isError($e = $smtp->connect())) { die($e->getMessage() . "\n"); } /* Send the 'MAIL FROM:' SMTP command. */ if (PEAR::isError($smtp->mailFrom($from))) { die("Unable to set sender to <$from>\n"); } /* Address the message to each of the recipients. */ foreach ($rcpt as $to) { if (PEAR::isError($res = $smtp->rcptTo($to))) { die("Unable to add recipient <$to>: " . $res->getMessage() . "\n"); } } /* Set the body of the message.*/ if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) { die("Unable to send data\n"); } //else{ echo "mail sended!";} /* Disconnect from the SMTP server. */ $smtp->disconnect(); //end sendmail } while($row_mailset= mysql_fetch_assoc($setformail)); mysql_free_result($row_mailset);
谁知道你是怎么搞得
$row_mailset= mysql_fetch_assoc($setformail);do
{
$tb='<table border="1" cellpadding="2" cellspacing="0" bordercolor="#FFCCCC"><tr>';
$j=0;
while ($j < $colnum)
{
$fname=mysql_field_name($setformail,$j);
$tb.='<td align=center><font size="2"><NOBR>'.array_search($fname,$mapnames).'</NOBR></font></td>';
$j++;
}
$tb.='</tr><tr>';
$td=0;
while($td<$colnum)
{
$fname=mysql_field_name($setformail,$td);
$tb.='<td align="center"><font size="2">'.$row_mailset[$fname],.'</font></td>';
//
$td++;
}
$tb.='</tr></table>';
$echos[]=$row_mailset["UserName"].'→'.$row_mailset["Email"];
//======send email 用pear来完成邮件发送
// print("<br>beging send a mail<br>");
require_once 'PEAR.php';
require_once 'Net/SMTP.php'; $from = '[email protected]';
$rcpt = array( $row_mailset["Email"]);
//define header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=gb2312\r\n";
//add headers to mail
$subj =$headers."Subject: 邮件测试发送!".$row_mailset["yyyymm"]."\n";
//test all mail table -- and tables tegether
$body=$tb;
/* Create a new Net_SMTP object. */
if (! ($smtp = new Net_SMTP($host))) {
/*without $host, mail still can be sended but it need to wait
a few minuts. */
die("Unable to instantiate Net_SMTP object\n");
} /* Connect to the SMTP server. */
if (PEAR::isError($e = $smtp->connect())) {
die($e->getMessage() . "\n");
} /* Send the 'MAIL FROM:' SMTP command. */
if (PEAR::isError($smtp->mailFrom($from))) {
die("Unable to set sender to <$from>\n");
} /* Address the message to each of the recipients. */
foreach ($rcpt as $to) {
if (PEAR::isError($res = $smtp->rcptTo($to))) {
die("Unable to add recipient <$to>: " . $res->getMessage() . "\n");
}
} /* Set the body of the message.*/
if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
die("Unable to send data\n");
}
//else{ echo "mail sended!";}
/* Disconnect from the SMTP server. */
$smtp->disconnect();
//end sendmail
}
while($row_mailset= mysql_fetch_assoc($setformail));
mysql_free_result($row_mailset);