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 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计