首页 > 解决方案 > 向 PHP 中的 2 个变量发送电子邮件

问题描述

我正在尝试向 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');

     }

    }

标签: php

解决方案


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


推荐阅读