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

时间:2016-06-03 09:10:54

标签: php email contact-form

编辑:

$recipient = "myemail@me.com";

不起作用,但

<? 
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 {
?>

像魅力一样。

我已收到联系表格,但我想使用联系表格向该人发送不同的电子邮件。

因此,点击订单时需要发送总共2封邮件(订单确认管理,订单确认给买家)

他/她的电子邮件地址存储在$ _SESSION [&#39; email&#39;]中,但如果我把它放在收件人字段中,我就无法工作...

{{1}}

2 个答案:

答案 0 :(得分:1)

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

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

然后像你一样邮寄

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

答案 1 :(得分:1)

编辑:也许您可以尝试将$_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页面发送多封电子邮件