2012-02-20 50 views
0

我在HTML格式如下:如何從表單中添加電子郵件到CC PHP腳本

<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 = '[email protected]',; 
$subject = 'New message from your website'; 
$headers = "From: [email protected]\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中添加填寫表單的電子郵件。 這怎麼可能。請幫幫我。

+3

唐不要讓人們將電子郵件從您的服務器發送到任意地址。你只是把自己變成垃圾郵件中繼。 – Quentin 2012-02-20 14:30:30

回答

1

而不是

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

嘗試(請注意你的 '頭' 的拼寫太):

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

噢。謝啦。 – Ion 2012-02-20 14:36:53

0

這可以工作,如果你糾正你的錯字;)

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

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