こんにちは、登録ユーザーであり、情報がデータベースに保存されている複数の電子メールを送信したいので、ここで私はphpスクリプトを使用して電子メールを送信したいと考えています。
ここに私のコードがあります
<?php
//Connect to database
$sql = "SELECT email FROM TABLENAME";
$res = mysql_query($sql) or die(mysql_error());
while( $row = mysql_fetch_assoc($res) )
{
$area = $row['email']. ", ";
// read the list of emails from the file.
$email_list = $area;
// count how many emails there are.
$total_emails = count($email_list);
// go through the list and trim off the newline character.
for ($counter=0; $counter<$total_emails; $counter++) {
$email_list[$counter] = trim($email_list[$counter]);
}
$to = $email_list;
echo $to;
}
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "newsletter@mydomain.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action=''>
Subject: <input name='subject' type='text' class='xl' /><br />
Message: <textarea name='message' cols='20' rows='10'></textarea><br />
<input type='submit' class='btn btn-primary' value='Send' />
</form>";
}
?>