Php表单:电子邮件副本发件人

时间:2012-12-03 00:36:11

标签: php forms contact

我有一个简单的表格。基本上尝试通过电子邮件复制共享认为这就足够了。我想将这封电子邮件的副本发送到$ email变量(是的,条款可能没有必要),有关如何操作的任何想法?通过谷歌遇到一堆帖子,但无法弄明白;

<?php
        $EmailFrom = "admin@test.com";
        $EmailTo  = "admin@test.com";
        $Subject = "Check out this video.";
        $email = !empty($_POST['email']) ? Trim(stripslashes($_POST['email'])) : false; 

        $Body = "Take a look at this; youtubelink...";

        $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
        header('Location: /#');
?>

2 个答案:

答案 0 :(得分:1)

只需添加另一封邮件();功能

<?php
        $EmailFrom = "admin@test.com";
        $EmailTo  = "admin@test.com";
        $Subject = "Check out this video.";
        $email = !empty($_POST['email']) ? Trim(stripslashes($_POST['email'])) : false; 

        $BodyReceiver = "Take a look at this; youtubelink...";
        $BodySender = "You sent the following message " . $BodyReceiver . " to " . $EmailTo . ".";

        $successReceiver = mail($EmailTo, $Subject, $BodyReceiver, "From: <$EmailFrom>");
        $successSender = mail($EmailFrom, $Subject, $BodySender, "From: <no-reply@text.com");
        header('Location: /#');
?>

或类似的......

正如bozdoz建议您可以使用密件抄送,但它将是原件的完整副本。您将无法更改发件人电子邮件或按摩(例如“您发送了以下按摩...到......”等等。

答案 1 :(得分:1)

只需像这样编辑您的脚本,只有原件出现时才会发送副本:

<?php
    $EmailFrom = "admin@test.com";
    $EmailTo  = "admin@test.com";
    $Subject = "Check out this video.";
    $email = !empty($_POST['email']) ? Trim(stripslashes($_POST['email'])) : false; 

    $Body = "Take a look at this; youtubelink...";

    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    if ($success)
        mail($EmailFrom, $Subject, $Body, "From: <$EmailFrom>");

    header('Location: /#');
?>