PHP Pear电子邮件格式错误

时间:2015-04-07 03:26:50

标签: php email format message

我知道标题很奇怪我不能说我的生活这句话很好笑。

我已经通过多种方式对问题进行了搜索,但没有显示任何内容。

我在网站im building上有电子邮件脚本工作,太棒了!但是当我编辑邮件代码以添加额外的消息行时,它会使序列出错。

这是我用于电子邮件区域的代码:

<?php

require_once "Mail.php";

// load the variables form address bar

$name = $_REQUEST["name"];
$subject = 'Customer Feedback';
$message = $_REQUEST["message"];
$from = $_REQUEST["from"];
$compname = $_REQUEST["companyName"];
$ph = $_REQUEST["phone"];
$acp = $_REQUEST['allowCommentPublish'];
$marketing = $_REQUEST['incmarketing'];
$verif_box = $_REQUEST["verif_box"];

// Checking the check boxes and marking as appropriate
if(isset($_POST['allowCommentPublish']))
        {
            $acp = 'Yes';
        }

    else
        {
            $acp = 'No';
        }

if(isset($_POST['incmarketing']))
        {
            $marketing = 'Yes';
        }

    else
        {
            $marketing = 'No';
        }

// Optional data checker
if($compname == '')
    {
        $compname = 'N/A';
    }

if($ph == '')
    {
        $ph = 'N/A';
    }

// remove the backslashes that normally appears when entering " or '
$name = stripslashes($name);
$message = stripslashes($message);
$subject = stripslashes($subject);
$acp = stripcslashes($acp);
$marketing = stripcslashes($marketing);
$from = stripslashes($from);

// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon'])
    {
        // if verification code was correct send the message and show this page
        $ToEmail = "email@email.com";

        $message = "Name: ".$name."\n".$message;
        $message = "From: ".$from."\n".$message;
        $message = "Comments: ".$message."\n".$message;
        $message = "Allow feedback to be Published: ".$acp."\n".$message;
        $message = "[ OPTIONAL DATA ]"."\n".$message;
        $message = "Company Name: ".$compname."\n".$message;
        $message = "Phone Number: ".$ph."\n".$message;
        $message = "Allow extra Marketing? ".$marketing."\n".$message;

        $headers = array ('From' => $from,
                  'To' => $ToEmail,
                  'Subject' => 'Feedback: '.$subject);

        $smtp = Mail::factory('smtp', array ('host' => 'smtp.vic.exemail.com.au', 'auth' => false));

        $mail = $smtp->send($ToEmail, $headers, $message);

        // delete the cookie so it cannot sent again by refreshing this page
        setcookie('tntcon','');

        header("Location: /feedback_sent.php");
        exit;
    } 
else 
    {
        // if verification code was incorrect then return to contact page and show error
        header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
        exit;
    }
?>

在我看来,这应该吐出消息正文:

姓名:姓名在这里 来自:电子邮件地址
评论:此处留言
允许发布反馈:响应
[可选数据]
公司名称:公司
电话号码:电话
允许额外营销:

这应该是它在电子邮件中看到的方式吗?

我真正得到的是:

允许发布反馈:响应
[可选数据]
公司名称:公司
电话号码:电话
允许额外的营销?响应
来自:电子邮件地址
姓名:这里的名字
评论:此处留言

这是正常的吗?或者我无意中将它扼杀在某个地方并且弄乱了我的脑袋作为付款?

感谢您提供任何帮助。

编辑:更新了代码。

<?php
// ----------------------------------------- 
//  The Web Help .com
// ----------------------------------------- 
// remember to replace your@email.com with your own email address lower in this code.

require_once "Mail.php";

// load the variables form address bar
$name = $_REQUEST["name"];
$subject = 'Customer Feedback';
$comment = $_REQUEST["message"];
$from = $_REQUEST["from"];
$compname = $_REQUEST["companyName"];
$ph = $_REQUEST["phone"];
$acp = $_REQUEST['allowCommentPublish'];
$marketing = $_REQUEST['incmarketing'];
$verif_box = $_REQUEST["verif_box"];

    // Checking the check boxes and marking as appropriate
    if(isset($_POST['allowCommentPublish']))
            {
                $acp = 'Yes';
            }

        else
            {
                $acp = 'No';
            }

    if(isset($_POST['incmarketing']))
            {
                $marketing = 'Yes';
            }

        else
            {
                $marketing = 'No';
            }

    // Optional data checker
    if($compname == '')
        {
            $compname = 'N/A';
        }

    if($ph == '')
        {
            $ph = 'N/A';
        }

// remove the backslashes that normally appears when entering " or '
$name = stripslashes($name);
$comment = stripslashes($comment);
$subject = stripslashes($subject);
$acp = stripcslashes($acp);
$marketing = stripcslashes($marketing);
$from = stripslashes($from);

    // check to see if verificaton code was correct
    if(md5($verif_box).'a4xn' == $_COOKIE['tntcon'])
        {
            // if verification code was correct send the message and show this page
            $ToEmail = "jim@digital2go.com.au";

            $message = "Name: ".$name."\n".$message;
            $message .= "From: ".$from."\n".$message;
            $message .= "Comments: ".$comment."\n".$message;
            $message .= "Allow feedback to be Published: ".$acp."\n".$message;
            $message .= "[ OPTIONAL DATA ]"."\n".$message;
            $message .= "Company Name: ".$compname."\n".$message;
            $message .= "Phone Number: ".$ph."\n".$message;
            $message .= "Allow extra Marketing? ".$marketing."\n".$message;

            $headers = array ('From' => $from,
                      'To' => $ToEmail,
                      'Subject' => 'Feedback: '.$subject);

            $smtp = Mail::factory('smtp', array ('host' => 'smtp.vic.exemail.com.au', 'auth' => false));

            $mail = $smtp->send($ToEmail, $headers, $message);

            // delete the cookie so it cannot sent again by refreshing this page
            setcookie('tntcon','');

            header("Location: /feedback_sent.php");
            exit;
        } 
    else 
        {
            // if verification code was incorrect then return to contact page and show error
            header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
            exit;
        }
?>

1 个答案:

答案 0 :(得分:1)

发表您的信息&#34;继续&#34;按照你希望的顺序:

    $message = "Name: ".$name."\n".$message;
    $message .= "From: ".$from."\n".$message;
    $message .= "Comments: ".$message."\n".$message;
    $message .= "Allow feedback to be Published: ".$acp."\n".$message;
    $message .= "[ OPTIONAL DATA ]"."\n".$message;
    $message .= "Company Name: ".$compname."\n".$message;
    $message .= "Phone Number: ".$ph."\n".$message;
    $message .= "Allow extra Marketing? ".$marketing."\n".$message;