dpy3846 2018-02-24 17:09
浏览 100
已采纳

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

I'm working on making an email PHP that sends me an email whenever someone completes my survey. I have all of these variables defined in my code and every single one of them works correctly and shows up in my email except the $phone variable. In that row of my code, I get a blank line. Why would that be?

<?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']."
";
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";

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

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

1条回答 默认 最新

  • doujia1988 2018-02-24 20:56
    关注

    In your line <td align="left" style="border: solid 1px black" $phone </td> you are missing an HTML closing tag. It should read <td align="left" style="border: solid 1px black"> $phone </td> instead.

    Please also take the other statements concerning security serious. This risk is often underrated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划