【问题标题】:how to send multiple email pick from database in php如何在php中从数据库中发送多个电子邮件选择
【发布时间】:2012-12-07 19:05:14
【问题描述】:

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

【问题讨论】:

  • 在每个循环中,$email_list = $area; 都会被覆盖。 count 用于数组而不是字符串
  • 您将$email_list 视为一个数组,但它只是$area 字符串的副本。你的意思是$email_list = explode(', ', $area);

标签: php email sendmail


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-06
    • 1970-01-01
    • 2017-01-17
    相关资源
    最近更新 更多