dongyou9818 2013-08-26 21:49
浏览 55
已采纳

使用php和postfix发送邮件

Thank you for taking the time to review my question. I have postfix set up on Centos 6.4 I am not very familiar with E-mail servers or PHP, but I would like to set up a simple sight to send emails using postfix. I was told I should use php. My current. (not working) source code is this...

<!doctype html>
<html>
<head>
<style type="text/css">
#mainContainer
{
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
}

#adressContainer
{
        width:100%;
        height:3%;
}

#buttonContainer
{
        width:100%;
        height:5%;
}

#bodyContainer
{
        width:100%;
        height:90%;
}

#address
{
        resize:none;
        width:100%;
        height:100%;
}

#bodyText
{
        resize:none;
        width:100%;
        height:100%;
}
</style>
<script>

        <?php
        function sendMail()
        {

                $to = "someone@somewhere"
                $subject = "Test mail";
                $message = "Hello! This is a simple email message.";
                $headers = "From:" . $from;
                mail($to,$subject,$message,$headers);
        }       
        ?>
</script>
<!--<link rel="stylesheet" type="text/css" href="email.css" />-->
</head>
<body>
        <div id="mainContainer">
                <div id="addressContainer">
                        <input id="adress" type="text" name="Adress: "></input>
                </div>

                <div id="buttonContainer">
                        <button type="submit" onclick="sendMail()">send</button>
                </div>

                <div id="bodyContainer">
                        <textarea id="bodyText">I love you whitney :) </textArea>
                </div>
        </div>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongzhi6146 2013-08-26 21:53
    关注

    PHP runs on the server. onClick executes Javascript on the CLIENT machine. You can NOT directly invoke PHP functions via Javascript code, or vice versa.

    What you're doing can be accomplished with a simple form:

    <?php
    
    if ($_SERVER["REQUEST_METHOD"]  == 'POST') {
        $to = $_POST['to'];
        $text = $_POST['text'];
        mail($to, .....);
    }
    
    ?>
    <form method="POST" action="">
        <input type="text" name="to" />
        <input type="text" name="text" />
        <input type="submit" />
    </form>
    

    There is no need to use Javascript at all.

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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮