【问题标题】:php form showing php file and not sending it onphp 表单显示 php 文件而不是发送它
【发布时间】:2014-07-22 09:06:59
【问题描述】:

我正在使用 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 '';
?>

我在通常会显示我的详细信息的地方放置了星星。我不完全确定这里的错误是什么。

【问题讨论】:

  • 这个页面的扩展名是什么?

标签: php phpmailer


【解决方案1】:

尝试改变这一行

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2013-12-31
        • 2013-08-27
        • 1970-01-01
        相关资源
        最近更新 更多