如何使我的网站联系表格给多个收件人(电子邮件)

时间:2018-04-19 22:42:14

标签: php html

如何使我的网络联系表单向多封电子邮件发送请求,并且每封电子邮件都不会看到其他人收到来自网络联系表单收到相同请求的电子邮件。我的代码工作正常,但只是将联系表单中的请求发送到一个电子邮件地址,如何将其发送到多个电子邮件,这是我的代码:

    <?php
     $name = $_POST['name']; // form field
     $email = $_POST['email']; // form field
     $message = $_POST['message']; // form field

     if ($_POST['submit']){
     $from = "Contact us<info@xxxxxx>"; //enter your email address
     $to = "xxxxxx@outlook.com"; //enter the email address of the contact your sending to
     $subject = "you have 6 pending mail"; // subject of your email
     $bcc = "";
    $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject, 'headers' => $headers);

    $text = ''; // text versions of email.
    $html = "<html><body>

    Name: $name <br> Email: $email <br>Message: $message <br>

    </body></html>"; // html versions of email.

    $crlf = "\n";

    $mime = new Mail_mime($crlf);
    $mime->setTXTBody($text);
    $mime->setHTMLBody($html);

    //do not ever try to call these lines in reverse order
    $body = $mime->get();
    $headers = $mime->headers($headers);

     $host = "localhost"; // all scripts must use localhost
     $username = "xxxxxxx"; //  your email address (same as webmail username)
     $password = "xxxxxx"; // your password (same as webmail password)

    $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
    'username' => $username,'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
    echo("<p>" . $mail->getMessage() . "</p>");
    }
    else {
    echo("<p>Message successfully sent!</p>");
    // header("Location: http://www.example.com/");
    }
      }
     ?>

     <form action="qservers_mail.php" method="post">
    <table border="0" style="background:#ececec" cellspacing="5">
    <tr align="left"><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
    <tr align="left"><td>Email address</td><td><input type="text" size="30" name="email"></td></tr>
    <tr align="left"><td valign="top">Comments</td><td><textarea name="message" rows="6" cols="30"></textarea></td></tr>
    <tr align="left"><td>&nbsp;</td><td><input type="submit" value="Send" name='submit'></td></tr>
    </table>
    </form>

1 个答案:

答案 0 :(得分:0)

用逗号分隔它们。

$to = "first@mail.ru, second@mail.ru";