Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将CC添加到php电子邮件脚本的标题并格式化php响应代码_Php_Email_Formatting_Cc - Fatal编程技术网

将CC添加到php电子邮件脚本的标题并格式化php响应代码

将CC添加到php电子邮件脚本的标题并格式化php响应代码,php,email,formatting,cc,Php,Email,Formatting,Cc,我有一个有效的电子邮件脚本。现在我想在CC中添加发件人的电子邮件,这样他们就可以得到电子邮件的副本。因此,我添加了$headers部分,在接收端的电子邮件中,它显示为CC'd,但CC'd电子邮件实际上没有收到电子邮件。有什么想法吗 <?php if($_POST) { $yourEmail = "myemail@business.com"; $fname = $_POST['fname'];

我有一个有效的电子邮件脚本。现在我想在CC中添加发件人的电子邮件,这样他们就可以得到电子邮件的副本。因此,我添加了$headers部分,在接收端的电子邮件中,它显示为CC'd,但CC'd电子邮件实际上没有收到电子邮件。有什么想法吗

    <?php
        if($_POST) {
            $yourEmail = "myemail@business.com";

            $fname = $_POST['fname'];
            $lname = $_POST['lname'];
            $email = $_POST['email'];
            $phone = $_POST['phone'];
            $message = $_POST['message'];
            $headers = 'From:' . $email . "\r\n" . 'Cc:' . $email . "\r\n";

            $responseRefresh = "Redirecting in 5 seconds.<br>";
            $responseFillData = "Please fill all the data.<br>";
            $responseValidEmail = "Please enter valid email.<br>";
            $responseCompleted = "Form successfully submitted.<br>";
            $responseFailed = "Form failed to be submitted.<br>";

            $response = "" . $responseRefresh;

            $hasError = false;
            if($fname == "" || $lname == "" || $email == "" || $phone == "") {
                $hasError = true;
                $response = $responseFillData . $response;
            }

            if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i", $email)) {
                $hasError = true;
                $response = $responseValidEmail . $response;
            }

            if($hasError) {
                header("refresh:5;url=index.html#contact");
                echo $response;
                return false;
            }

            $text = "Voornaam: $fname \n
                Familienaam: $lname \n
                E-mailadres: $email \n
                Telefoonnummer: $phone \n
                Bericht: \n
                $message";

            if(mail($yourEmail, $fname . " " . $lname . " sent a message via de DDW website", $text, $headers)) {
                $response = $responseCompleted . $response;
            }
            else {
                $response = $responseFailed . $response;
            }

            header("refresh:5;url=index.html#contact");
            echo $response;
        }
    ?>

接下来,我还要格式化响应消息。我尝试向消息中添加一些html元素,但似乎不起作用。如何在“成功”响应中添加我的图像

例如:

$responseCompleted = "Form successfully submitted. <img src="http://www.ddw-sanitair.be/img/vink.png"><br>";
$responseCompleted=“表单已成功提交。
”;
邮件不会被发送到收件箱有多种原因-即使
邮件
函数返回true。使用
\r\n
而不是
\n
。另外,试着使用一个唯一的抄送地址来测试。我让它工作了(见上面更新的帖子),但是抄送的电子邮件实际上没有收到电子邮件?!邮件不会被发送到收件箱有多种原因-即使
Mail
函数返回true。使用
\r\n
而不是
\n
。另外,试着使用一个唯一的抄送地址来测试。我让它工作了(见上面更新的帖子),但是抄送的电子邮件实际上没有收到电子邮件?!