在PHP

时间:2018-06-12 08:37:04

标签: php

我试图向2个变量发送电子邮件,目前我试图将3封电子邮件添加到数组并将其放入变量并从表单中获取其他电子邮件,然后我不知道如何将这两个变量放在一起发送时,他们每个人都有自己的“to”但这不起作用或什么不是,我不知道是什么?是的,我有真正的电子邮件,我使用这些是这个占位符!!!

<?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['submit'])) {
    $email = $_POST['LOGSE'];
    $email2 = array("test@test.com", "test@test.com", "test@test.com");
    $name = $_POST['full_name'];
    $eventtitle =  $_POST['EventT'];
    $InCharge =  $_POST['InCharge'];
    $Venue =  $_POST['Venue'];
    $VenY =  $_POST['VenR'];
    if($VenY != "Yes"){
        $ava = " Have not checked if";
    }
    else{
        $ava = "";
    }
    $dates = $_POST['dateS'];
    $datee = $_POST['dateE'];
    $adults =  $_POST['Adults'];
    $children =  $_POST['Children'];
    $catreq =  $_POST['CateReq'];
    if (catreq != ''){
        $catreq = $catreq;
    }
    else{
    $catreq = "No Catering Needed";

    }

    $logreq =  $_POST['LogReq'];
    if (logreq != ''){

    $logreq = $logreq;
    }
    else{
        $logreq = "No Logistic Equipment Needed";

    }
    $itreq =  $_POST['ITReq'];
    if (itreq != ''){

    $itreq = $itreq;
    }
    else{
    $itreq = "No IT Needed";

    }
    $tran =  $_POST['TransR'];
    if($tran != Yes){

        $tran = "NO ";


    }
    else{
        $tran = "";

    }
    $Risk =  $_POST['RiskR'];
    if($Risk != Yes){

        $Risk = "NO ";


    }
    else{
        $Risk = "";

    }
    $othern =  $_POST['OtherN'];

    // The Email:
    $from      = 'test@test.com';
    $to      = $email;
    $to      = $email2;
    $subject = 'Event Form ' .$eventtitle;
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type:text/html;charset=UTF-8' . "\r\n";
    $headers .= 'From: Event Form<test@test.com>' . "\r\n";
    $headers .= 'Cc: test@test.com, test@test.com' . "\r\n";
    $body = '<html>
        <head>
            <title>Event</title>
            <style>
                h1 {
                    font-family: "Century Gothic", CenturyGothic, 
AppleGothic, sans-serif;
                } 
                h3 {
                    font-family: "Century Gothic", CenturyGothic, 
AppleGothic, sans-serif;
                }
            </style>
        </head>
        <body>
            <h1>Event Details</h1>

            <h3>Name: '.$name.'</h3>
            <h3>Event Title: '.$eventtitle.'</h3>
            <h3>Event Manager: '.$InCharge.'</h3>
            <h3>Venue: '.$Venue.' - '.$ava.' Available</h3>
            <h3>Date Start: '.$dates.'</h3>
            <h3>Date End: '.$datee.'</h3>
            <h3>Adults Attending: '.$adults.'       Children Attending: 
'.$children.'</h3>
            <h3>Catering Requirements: '.$catreq.'</h3>
            <h3>Logistic Requirements/Equipment: '.$logreq.'</h3>
            <h3>IT Requirements: '.$itreq.'</h3>
            <h3>Other Notes: '.$othern.'</h3>
            <h3><font color="red">'.$tran.'</font>Transport Has Been 
Booked</h3>

        </body>
    </html>' . "\r\n";





    mail( $to, $subject, $body ,$headers );

        /* echo "An Email Has Been Sent<br>Thank You."; */
        header('Location: ./thanks.html');

     }

    }

4 个答案:

答案 0 :(得分:2)

邮件中的$ to函数应该是一个字符串。如果有多个电子邮件地址,则应以逗号分隔。在您的情况下,您可能需要执行以下操作。     $ to = $ email。 &#39;&#39 ;. implode(&#39;,&#39;,$ email2);

答案 1 :(得分:0)

这没有意义:

$to      = $email;
$to      = $email2;

Parmae​​ter $ to应该是一串逗号分隔的电子邮件地址,例如:

$to = $email1 . ", " . $email2 . ", " . $email3;

答案 2 :(得分:0)

使用逗号

添加电子邮件地址
$email_to = "test@test.com,some@other.com,yet@another.net";

您也可以添加

$headers = "Bcc: someone@domain.com";

答案 3 :(得分:0)

在阵列上使用foreach

foreach($email2 as $to){
    mail( $to, $subject, $body ,$headers );
}

或者像其他人一样暗示:

$to = $email.",".implode(",",$email2);