dtzk85937 2015-05-01 15:44
浏览 35
已采纳

我的php邮件功能正在发送空白邮件

So as the title states I receive blank emails from my contact form. The php code is below. I've checked the value of $msg and it appears correctly, I've also googled a ton and I can't find anything standard cause that apply to me.

<?php
main();

function main() {
    $posted = setVariables();
    $msg = setMessage($posted);
    $result = sendMail($msg);
    userFeedback($result);
}

function setVariables() {
    $name;
    if (isset($_POST['name'])){
        $name=$_POST['name'];
        if ($name == null) {
            $name = "ERROR - name is null";
        }
    }

    $email;
    if (isset($_POST['email'])){
        $email=$_POST['email'];
        if ($email == null) {
            $email = "ERROR - email is null";
        }
    }

    $enquiry;
    if (isset($_POST['enquiry'])){
        $enquiry=$_POST['enquiry'];
        if ($enquiry == null) {
            $enquiry = "ERROR - enquiry is null";
        }
    }

    $message;
    if (isset($_POST['message'])){
        $message=$_POST['message'];
        if ($message == null) {
            $message = "ERROR - message is null";
        }
    }

    $posted = array($name,$email,$enquiry,$message);
    return $posted;
}

function setMessage($posted) {
    $msg = "Name: " . $posted[0] . "
Email: " . $posted[1] . "
Enquiry: " . $posted[2] . "
Message: " . $posted[3];
    $msg = wordwrap($msg,70);
    $msg = Trim(stripslashes($_POST['Message']));
    return $msg;
}

function sendMail($msg) {
    $result = mail("social@georgeappleton.co.uk","Contact From Portfolio",$msg, "From: <info@yourdomain.co.uk>");
    return $result;
}

function userFeedback($result) {
    if ($result == false) {
        echo "Message failed to send, please inform me through my email address. social@georgeappleton.co.uk";
    } else {
        echo "Message Sent!<br/><br/>Returning you to <a href='http://www.georgeappleton.co.uk'>georgeappleton.co.uk</a> in 5 seconds";
    }
    echo "<script>setTimeout(function() {window.location = 'http://www.georgeappleton.co.uk';},5000);</script>";
}
?>

Thanks guys, appreciate it a lot

-Shardj

  • 写回答

2条回答 默认 最新

  • douyong6589 2015-05-01 15:55
    关注

    Get rid of this line:

    $msg = Trim(stripslashes($_POST['Message']));
    

    It's overwriting $msg with the contents of a nonexistent parameter. It already contains the message text, which was in $posted[3].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?