0

嗨,我想发送多封已注册用户的电子邮件,并且信息已保存在数据库中,所以在这里我想使用 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>";
            }
            ?>
4

1 回答 1

0

您的问题不清楚,就像您编写的代码一样-

邮件(“newsletter@mydomain.com”,“主题:$subject”,$message,“发件人:$email”);在上面的代码块中,第一个参数应该是您创建的名称为 $area 的列表。

无论如何,我认为你应该尝试一次mail_queue lib。

于 2012-12-20T09:58:49.370 回答