PHP邮件$ email = $ _POST ['email']在$ recipients中

时间:2013-01-09 17:48:25

标签: php

我有以下php邮件文件:

<?php $name = $_POST['name'];
$email = $_POST['email'];
$choice = $_POST['choice'];$num = $_POST['num'];
$choice1 = $_POST['choice1'];$num1 = $_POST['num1'];
$phone= $_POST['phone'];
$town= $_POST['town'];
$formcontent="
Name: $name \n
Number: $phone \n
Choice: $choice Amount:$num
Choice: $choice1 Amount:$num1
Town: $town \n
Email: $email" ;
$recipient = "info@domain.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";?>

我可以将$ email添加到收件人吗?我想将表单中输入的电子邮件添加到接收电子邮件的收件人中。 (info@domain.com和表格中输入的电子邮件($ email = $ _POST ['email'];)将收到该电子邮件。

1 个答案:

答案 0 :(得分:2)

您可以使用逗号分隔多个电子邮件地址$recipient。试试这个。

$recipient = "info@domain.com, $email";

修改

以下是整个事情。

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $choice = $_POST['choice']; $num = $_POST['num'];
    $choice1 = $_POST['choice1']; $num1 = $_POST['num1'];
    $phone= $_POST['phone'];
    $town= $_POST['town'];

    $formcontent = "
    Name: $name \n
    Number: $phone \n
    Choice: $choice Amount:$num
    Choice: $choice1 Amount:$num1
    Town: $town \n
    Email: $email";

    $recipient = "info@domain.com, $email";
    $subject = "Contact Form";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "Thank you";

?>