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

使用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.

    点赞 打赏 评论

相关推荐 更多相似问题