PHP代码不通过电子邮件发送

时间:2018-02-24 17:09:37

标签: php html

我正在制作电子邮件PHP,只要有人完成我的调查,就会向我发送电子邮件。我在我的代码中定义了所有这些变量,并且每一个变量都能正常工作并显示在我的电子邮件中,除了$ phone变量。在我的代码行中,我得到一个空白行。为什么会这样?

<?PHP
/* message */
        $name = $_POST['name'];
        $address = $_POST['address'];
        $address2 = $_POST['address2'];
        $fulladdress = $address . ", " . $address2;
        $city = $_POST['city'];
        $state = $_POST['state'];
        $zipcode = $_POST['zipcode'];
        $city_state_zip = $city . ", " . $state . " " . $zipcode;
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $phone = "(" . substr($phone, 0, 3). ") " . substr($phone, 3, 3) . "-" . substr($phone,6,4);
        $years_experience = $_POST['years_experience'];
        $education_level = $_POST['education_level'];
        $salary = $_POST['salary'];
        $current_employer = $_POST['current_employer'];
        $previous_employer1 = $_POST['previous_employer1'];
        $previous_employer2 = $_POST['previous_employer2'];
        if( empty($previous_employer2) AND empty($previous_employer1) ) {
            $previous_employers = "None";
        }
        elseif(empty($previous_employer2)) {
            $previous_employers = $previous_employer1;
        }
        else{
            $previous_employers = $previous_employer1 . " and " . $previous_employer2;
        }
        $grad_year = $_POST['grad_year'];

        $class_size = $_POST['class_size'];
        $department_feedback = $_POST['department_feedback'];
        $wishes = $_POST['wishes'];
        /* $size = count($useful_classes);
        $classes="";
        foreach ($useful_classes as $key => $value){ 
                        $classes .= $value;
                        if($size > ($key + 1)){
                            $classes .= ", ";
                        }
                    }

        $size2 = count($skills);
        $skillsets="";
        foreach ($skills as $key => $value){ 
                        $skillsets .= $value;
                        if($size2 > ($key + 1)){
                            $skillsets .= ", ";
                        }
                    } */
        $restaurant = $_POST['restaurant'];         
        $hobbies = $_POST['hobbies'];
        $kstate_memory = $_POST['kstate_memory'];

$messageTT ="";
$messageTT .= <<<EOT
<html>
<head>
<title></title>
</head>
<body>
    <table style="border-collapse: collapse">
            <tr>
                <td align="right" style="border: solid 1px black"> <b>Name:</b> </td>
                <td  align="left" style="border: solid 1px black"> $name </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Address:</b> </td>
                <td  align="left" style="border: solid 1px black"> $fulladdress </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> </td>
                <td  align="left" style="border: solid 1px black"> $city_state_zip </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Email:</b> </td>
                <td  align="left" style="border: solid 1px black"> $email </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Phone:</b> </td>
                <td align="left" style="border: solid 1px black" $phone </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Years of Professional Experience:</b> </td>
                <td align="left" style="border: solid 1px black"> $years_experience </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Education Level:</b> </td>
                <td align="left" style="border: solid 1px black"> $education_level </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Salary Ranking:</b> </td>
                <td  align="left" style="border: solid 1px black"> $salary </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Current Employer:</b> </td>
                <td  align="left" style="border: solid 1px black"> $current_employer </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b> Past Employer(s): </b></td>
                <td  align="left" style="border: solid 1px black"> $previous_employers </td>
            </tr>
            <tr>
                <td align="right" style="border: solid 1px black"> <b>Graduation Year: </b> </td>
                <td  align="left" style="border: solid 1px black"> $grad_year </td>
            </tr>
            <tr>
                <td align="right" style="border: solid 1px black"> <b>Most Useful Classes:</b> </td>
                <td  align="left" style="border: solid 1px black"> $classes </td>
            </tr>
            <tr>
                <td align="right" style="border: solid 1px black"> <b>Most Useful Skills: </b> </td>
                <td  align="left" style="border: solid 1px black"> $skillsets  </td>
            </tr>
            <tr>
                <td align="right" style="border: solid 1px black"> <b>Class Size: </b> </td>
                <td  align="left" style="border: solid 1px black"> $class_size  </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b> Department Feedback: </b></td>
                <td  align="left" style="border: solid 1px black"> $department_feedback </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b> Wishes for Next Generation: </b></td>
                <td  align="left" style="border: solid 1px black"> $wishes </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Favorite Restaurant: </b> </td>
                <td  align="left" style="border: solid 1px black"> $restaurant </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>What You Do for Fun: </b> </td>
                <td  align="left" style="border: solid 1px black"> $hobbies </td>
            </tr>
            <tr>
                <td  align="right" style="border: solid 1px black"> <b>Favorite K-State Memory: </b> </td>
                <td  align="left" style="border: solid 1px black"> $kstate_memory </td>
            </tr>
        </table>
</body>
</html>
EOT;

/* recipients */
$to  = "anon <anon@anon.edu>";

/* subject */
$subject = " Survey Form Submission -- " . $_POST['name'];;

//$headers = 'From: '.$_POST['email']."\n";
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\n";

/* additional headers */
$headers .= 'From: '.$_POST['name'].' <'.$_POST['email'].">\n";
//Next two lines for cc and bcc....
//$headers .= "Cc: birthdayarchive@example.com\r\n";
//$headers .= "Bcc: birthdaycheck@example.com\r\n";

/* and now mail it */
mail($to, $subject, $messageTT, $headers);
?>

1 个答案:

答案 0 :(得分:1)

在你的队伍中 <td align="left" style="border: solid 1px black" $phone </td> 您缺少HTML结束标记。 它应该读 而是<td align="left" style="border: solid 1px black"> $phone </td>

请同时采取其他有关安全问题的陈述。这种风险经常被低估。