php表单显示php文件而不是发送它

时间:2014-07-22 09:06:59

标签: php phpmailer

我正在使用php邮件程序脚本。当我点击表格提交时。它不是发送电子邮件,而是在我的浏览器窗口中显示php文件脚本:

<form action="mail.php" method="post" style="margin-top: 60px;">
    <input type="text" placeholder="Full name..." name="emailName">
    <input type="text" placeholder="You@example.com..." name="emailFrom">
    <input type="text" placeholder="Telephone Number..." name="emailTel">

    <button class="body">Send</button>
</form>

<script type="text/javascript">
    function MM_goToURL() { //v3.0
        var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
        for (i=0; i<(args.length-1); i+=2) 
            eval(args[i]+".location='"+args[i+1]+"'");
    }
</script>
</head>
<body onLoad="MM_goToURL('parent','<?php echo $_POST["emailSource"] ?>?sent=y');return document.MM_returnValue">
<?php
    require 'c:\php\includes\PHPMailerAutoload.php';
    $mail = new PHPMailer;

    $mail->isSMTP();                    // Set mailer to use SMTP
    $mail->Host = '***********';        // Specify main and backup server
    $mail->SMTPAuth = ***********;      // Enable SMTP authentication
    $mail->Username = '***********';    // SMTP username
    $mail->Password = '***********';    // SMTP password
                                        // Enable encryption, 'ssl' also accepted
    $mail->Port = 587;
    $mail->From = '***********';
    $mail->FromName = '***********';
    $mail->addAddress($_POST["emailTo"]); // Name is optional
    $mail->WordWrap = 50;                 // Set word wrap to 50 characters
    $mail->isHTML(true);                  // Set email format to HTML

    if (isset($_FILES['docload']) && $_FILES['docload']['error'] == UPLOAD_ERR_OK) {
        $mail->AddAttachment($_FILES['docload']['tmp_name'],
                             $_FILES['docload']['name']);
    }

    $mail->Subject = $_POST["emailSubject"];
    $mail->Body    = 'Name: ' . $_POST["emailName"] . '<br>Email: ' . $_POST["emailFrom"] . '<br>Tel: ' . $_POST["emailTel"];

    if(!$mail->send()) {
       echo 'Message could not be sent.';
       echo 'Mailer Error: ' . $mail->ErrorInfo;
       exit;
    }

    echo '';
?>

我已将星星放在我的细节通常显示的位置。我不完全确定这里的错误是什么。

3 个答案:

答案 0 :(得分:2)

尝试更改此行

$mail->Body="Name: ".$_POST['emailName']."<br>Email: ".$_POST['emailFrom']."<br>Tel: ". $_POST['emailTel'];

答案 1 :(得分:1)

听起来很愚蠢,但是你确定文件以.php结尾吗?

答案 2 :(得分:1)

如果您可以在浏览器中看到PHP文件,那么您的服务器上的PHP未正确安装。