从 $_SESSION['email'] 添加第二个电子邮件地址并发送 2 封邮件

Add a second email address from $_SESSION['email'] and send 2 mails

编辑:

$recipient = $_SESSION['email'];

不起作用,但是

$recipient = "myemail@me.com";

很有魅力。


我有联系表,但我想向使用联系表的人发送另一封电子邮件。

所以他们点击订单时总共需要发送 2 封邮件(用于管理的订单确认,以及一封给买家的订单确认)

His/hers 电子邮件地址存储在 $_SESSION['email'] 中,但如果我将它放在收件人字段中,我将无法使用...

<? 
if ($_SERVER['REQUEST_METHOD'] == "POST") { 
    if (!$_POST['currentamount'] && !$_POST['nextamount']) { 
        $error_msg ="- You have to order atleast one ticket.<br>"; 
    } 
    if ($_POST['currentamount'] && !$_POST['date1']) { 
        $error_msg ="- You didn't select a date for the current show<br>"; 
    } 
    if ($_POST['nextamount'] && !$_POST['date2']) { 
        $error_msg ="- You didn't select a date the the next show.<br>"; 
    } 

    if (!empty($error_msg)) { 
        //Een van de velden werd niet goed ingevuld 
        echo "<b>Your message can't be send due to the following reason:</b>    <br><br>"; 
        echo $error_msg; 
        echo "<br>Click on <a href='javascript:history.back(1)'>Go back</a> and provide us with the needed information.<br><br>"; 
    } else {
        $recipient = "tickets@*******.com"; //Het email adres van de persoon die vragen moet ontvangen.
        $subject = "MTP: Ticket Order"; //Subject van de mail.
        $header = "From: noreply@*********";
        $mail_body = "Contact script werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n";
        $mail_body .= "De volgende persoon zou graag kaarten bestellen:\n";
        $mail_body .= "Naam: " . $_POST['name2'] . "\n";
        $mail_body .= "Met als kaartnummer: " . $_POST['card2'] . "\n\n";
        $mail_body .= "For the " . $_POST['currentshow'] . ", ". $_POST['name2'] ." would like ". $_POST['currentamount'] ." tickets on date: " . $_POST['date1'] . ".\n";
        $mail_body .= "For the " . $_POST['nextshow'] . ", ". $_POST['name2'] ." would like ". $_POST['nextamount'] ." tickets on date: " . $_POST['date2'] . ".\n";
        $mail_body .= "This gives us a total of : " . $_POST['total2'] . " EUR\n";
        $mail_body .= "\n\n -- ****** --";
        mail($recipient, $subject, $mail_body, $header);
        print "<b>IMPORTANT!</b>";
        print "<br><br>Thank you for your reservation.";
        print "<br><br>We are looking forward to meet you.";
    }              
} else {
?>

您应该像这样设置收件人变量:

$user_mail =  $_SESSION['email'];
$recipient = "tickets@*******.com,$user_mail";

然后像以前一样邮寄

mail($recipient, $subject, $mail_body, $header);

编辑:也许您可以尝试将 $_SESSION['email'] 作为字符串存储在变量 $recipient 中。所以在将电子邮件存储在收件人变量中之前将其转换为字符串,它可以工作。

实际上,您可以使用带有 2 个邮件程序调用的操作页面,一个用于向管理员发送电子邮件,另一个用于向客户发送电子邮件。你可以尝试这样的事情:

<?php
// email_sender and email_desitination
$sender_name = "My Name";
$mail_sender = "no-reply@example.com";
$mail_recipient = "customer@gmail.com";

//  subject and mail body
$mail_subject = "Your subject";
$mail_body = "Your message";

// mail headrs
// section for From and some Cc, Bcc, ReplyTo e X-Mailer
$mail_headers = "From: " .  $sender_name . " <" .  $mail_sender . ">\r\n";
$mail_headers .= "Reply-To: " .  $mail_sender . "\r\n";
$mail_headers .= "X-Mailer: PHP/" . phpversion();

if (mail($mail_recipient, $mail_subject, $mail_body, $mail_headers))
  echo "Message sent " . $mail_sender;
else
  echo "Error.";

// second email

// email_sender and email_desitination
$sender_name = "My Name";
$mail_sender = "no-reply@example.com";
$mail_recipient = "customer@gmail.com";

//  subject and mail body
$mail_subject = "Your subject";
$mail_body = "Your message";

// mail headrs
// section for From and some Cc, Bcc, ReplyTo e X-Mailer
$mail_headers = "From: " .  $sender_name . " <" .  $mail_sender . ">\r\n";
$mail_headers .= "Reply-To: " .  $mail_sender . "\r\n";
$mail_headers .= "X-Mailer: PHP/" . phpversion();

if (mail($mail_recipient, $mail_subject, $mail_body, $mail_headers))
  echo "Message sent " . $mail_sender;
else
  echo "Error.";


?>

您可以从同一个 action.php 页面发送多封电子邮件