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.

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

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历