Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHPmailer向多个地址发送电子邮件_Php_Html - Fatal编程技术网

使用PHPmailer向多个地址发送电子邮件

使用PHPmailer向多个地址发送电子邮件,php,html,Php,Html,当我可以向多个电子邮件帐户发送消息时,我正在创建一个网站。我的HTML如下所示: <!doctype html> <html> <head> <title>Saada</title> </head> <form action="test1.php" method="POST"> <body> <he

当我可以向多个电子邮件帐户发送消息时,我正在创建一个网站。我的HTML如下所示:

    <!doctype html>
    <html>
      <head>

        <title>Saada</title>
      </head>
      <form action="test1.php" method="POST">
      <body>
        <header>Küsitluse pealkiri</header>
          <br>
        <ol>
        <li>testb@localhost <input type="button" value="X"><br> <br>
        </ol>

        <input ><input type="button" value="Lisa adressaat"> <br> <br>Tekst adressaadile:<br>

        <textarea rows='4' name='tekst'></textarea>

        <br><footer>


        <INPUT TYPE="submit" VALUE="Saada" NAME="Saada">
        </form>

        <FORM METHOD="LINK" ACTION="Minu küsitlused.html">
        <INPUT TYPE="submit" VALUE="Loobu">


        </footer> 
      </body>
    </html>

萨阿达
Küsitluse pealkiri

  • testb@localhost



    Tekst Adressadile:

  • 我的PHP代码如下(我正在使用PHPMailer):

    
    
    在某种程度上,我使它起了作用。我在文本字段中插入的消息将发送到PHP代码中定义的电子邮件地址。在这种情况下,它是
    testb@localhost
    $mail->AddAddress('testb@localhost);
    )。我现在想做的是,当我将新的电子邮件地址插入HTML站点上较小的文本框中,并单击名为Lisa Adressat的提交按钮时,电子邮件将出现在上面的列表中(此时为
    testb@localhost
    )当我点击Saada时,电子邮件将发送到列表中的所有电子邮件地址。我应该向代码中添加什么来实现这一点


    提前感谢

    获取所有电子邮件地址并将其存储在阵列中。一旦它们进入数组,就只需要在所有的数组上循环

    $mailaddresses; //this is the array with the emailadresses, store the emailaddresses here
    foreach($mailaddresses as $mailaddress)
    {
        $mail->AddAddress($mailaddress);
    }
    
    编辑:从输入字段获取电子邮件地址,其中电子邮件地址用逗号分隔

    在html中:

    <input type="text" value="" name="mail">
    

    附加信息:
    str_replace
    是为了去除可能在逗号之后或之前插入的空格
    explode
    将字符串拆分为逗号所在的位置,并将其作为值数组返回。

    只需编写一个foreach语句即可

    $emails_sent = array();
    
    foreach ($emails as $key => $value) {
        $mail->AddAddress($value, $value);
        $emails_sent[$value] = (int) $mail->Send();
        $mail->ClearAddresses();
    }
    

    $emails将是您的电子邮件列表

    只需用逗号分隔多封电子邮件即可。它会工作的。谢谢,但是我如何将它们插入数组。对不起,我是初学者。你是如何发布电子邮件地址的?这是一个输入字段,您是用逗号分隔它们还是…?是的,这是一个文本字段,我用逗号分隔它们。@user244902如果这对您有效,请不要忘记接受答案。
    $mailaddresses = explode(',', str_replace(' ', '', $_POST['mail']));
    //the foreach loop goes here
    
    $emails_sent = array();
    
    foreach ($emails as $key => $value) {
        $mail->AddAddress($value, $value);
        $emails_sent[$value] = (int) $mail->Send();
        $mail->ClearAddresses();
    }