【问题标题】:Send emails with textarea value to all users from database with jquery使用 jquery 从数据库向所有用户发送带有 textarea 值的电子邮件
【发布时间】:2016-08-01 22:56:19
【问题描述】:

我正在尝试使用来自 textarea 的值从数据库向所有用户发送电子邮件。但我在这里做错了什么。我认为问题出在从数据库中选择数据的地方,因为如果我手动添加一个电子邮件地址,它就可以工作。

HTML

<textarea name="banner-text" id="banner-text" placeholder="Escrever…" ><?php echo $baner['banner']; ?></textarea>
<button type="submit" name="send-email" id="send-email" onClick="return false" >Notification</button>

$(function(){
     $("#send-email").click(function(){
        var n = $("#banner-text").val();
        $.ajax({
                 url: 'noti-per-email.php',
                 type: 'POST',
                 data: { baner_text:n },
                 success: function(data) { console.log(data) }
        });
    });
 });

PHP 文件

connection...

$banner = ($_POST['baner_text']);
$banner_message = str_replace("\n.", "\n..", $banner );

$sql_clients = "SELECT email FROM clients";
$result_clients = $conn->query($sql_clients);

        while($row = mysql_fetch_array($result_clients)){
            $emails = $row['email'] . ",";
        }

    $to      = $emails;
    $subject = '';

    mail($emails, $subject, $banner_message);   

【问题讨论】:

  • 您似乎一直在覆盖您的 $emails 变量。而是尝试将每个值添加到数组中。
  • 你怎么知道“你在这里做错了什么”?什么不工作?

标签: jquery mysql ajax database email


【解决方案1】:

您没有在这部分中包含额外的电子邮件

$result_clients = $conn->query($sql_clients);

        while($row = mysql_fetch_array($result_clients)){
            $emails = $row['email'] . ",";
        }

值被覆盖。代替$emails = ...,使用$emails .= ...

.= 将额外的文本添加到字符串中,而= 会覆盖它。

【讨论】:

    猜你喜欢
    • 2015-02-24
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 2013-12-03
    • 2014-11-23
    • 1970-01-01
    • 2021-03-26
    相关资源
    最近更新 更多