如何将FORM中的电子邮件添加到CC php脚本中

时间:2012-02-20 14:28:07

标签: php

我在html中有以下表格:

<form action="email.php" class="form">
    <fieldset>
    <legend>Formular contact</legend>

    <p class="nume">
        <input type="text" name="nume" id="nume" />
        <label for="nume">Nume</label>
    </p>

        <p class="prenume">
        <input type="text" name="prenume" id="prenume" />
        <label for="nume">Prenume</label>
    </p>

    <p class="companie">
        <input type="text" name="companie" id="companie" />
        <label for="companie">Companie</label>
    </p>

    <p class="email">
        <input type="text" name="email" id="email" />
        <label for="email">E-mail</label>
    </p>

    <p class="telefon">
        <input type="text" name="telefon" id="telefon" />
        <label for="telefon">Telefon</label>
    </p>

    <p class="text">
        <textarea name="text"></textarea>
        <label for="text">Mesaj</label>
    </p>


    <p class="submit">
        <input type="submit" value="Trimite">
        <input type="reset" value="Sterge" onClick="form()" />
    </p>
    </fieldset>
</form>

以及以下php脚本:

<?php
$field_name = $_POST['nume'];
$field_firstname = $_POST['prenume'];
$field_companie = $_POST['companie'];
$field_email = $_POST['email'];
$field_message = $_POST['comentariu'];

$mail_to = 'example@gmail.com',;
$subject = 'New message from your website';
$headers = "From: comentariu@domain.com\r\n" .
**$hearders .= "Cc: .$_GET['email']\r\n";**
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


$body = '<html><body>';
$body .= '<img src="http://www.bgd-group.ro/images/email.jpg" alt="BGD-GROUP" />';
$body .= '<p><center><strong><font color="red">Tabelul de mai jos contine datele completate de client pe site</font></strong></center></p>';
$body .= '<table rules="all" style="border-color: #666;" border="3" cellpadding="14">';
$body .= "<tr style='background: #eee;'><td><strong>Label</strong> </td><td><strong>Informatii client de pe site</strong></td></tr>";
$body .= "<tr><td><strong>Nume:</strong> </td><td>" . strip_tags($_GET['nume']) . "</td></tr>";
$body .= "<tr><td><strong>Prenume:</strong> </td><td>" . strip_tags($_GET['prenume']) . "</td></tr>";
$body .= "<tr><td><strong>Companie:</strong> </td><td>" . strip_tags($_GET['companie']) . "</td></tr>";
$body .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_GET['email']) . "</td></tr>";
$body .= "<tr><td><strong>Telefon:</strong> </td><td>" . strip_tags($_GET['telefon']) . "</td></tr>";
$body .= "<tr><td><strong>Mesaj:</strong> </td><td>" . strip_tags($_GET['comentariu']) . "</td></tr>";
$body .= "</table>";
$body .= "</body></html>";

//pana aici

$mail_status = mail($mail_to, $subject, $body, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Multumim pentru mesaj! Va vom contacta noi in cel mai scurt timp posibil');
        window.location = 'index.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Mesajul nu a fost trimis! Va rugam reincercati.');
        window.location = 'contact2.html';
    </script>
<?php
}
?>

粗线是我想要添加的内容。 $ hearder。=“抄送:来自表格的电子邮件\ r \ n”; 我想在CC中添加填写在表单中的电子邮件。 怎么可能呢。请帮帮我。

2 个答案:

答案 0 :(得分:1)

而不是

$hearders .= "Cc: .$_GET['email']\r\n";

尝试(注意你的'标题'的拼写):

$headers .= "Cc: ".$_GET['email']."\r\n";

答案 1 :(得分:0)

如果你纠正错字,这可以奏效;)

**$hearders .= "Cc: .$_GET['email']\r\n";**

$headers .= "Cc: .$_GET['email']\r\n";