PHP代码不会重定向到页面,但会显示空白页面

时间:2018-01-11 19:20:37

标签: php

<button mat-button [matMenuTriggerFor]="menu">Menu</button>
<mat-menu #menu="matMenu" overlapTrigger="false">
  <button mat-menu-item>Item 1</button>
  <button mat-menu-item>Item 2</button>
</mat-menu>

这是我的PHP已成功发送,但显示空白页面并且不会重定向到标题链接。

1 个答案:

答案 0 :(得分:-1)

如果我不得不猜我会说某些东西会导致输出到浏览器。无论是杂散回声还是打印,还是在php标签之前/之后的空格,或者错误/异常和错误被抑制。下面的代码将帮助它生成导致输出生成的邮件功能,但如果输出发生在if语句之前就不会发生。

作为奖励,您可以更快地将控制权返回给浏览器,并在用户重定向后继续处理电子邮件。

<?php
if (isset($_POST) && !empty($_POST))
{
    // move header up, add ignore user abort for safety.
    ignore_user_abort( TRUE );
    header("Location:http://www.prymage.com/thankyou.html");

    //pre-defined vals
    $to = "salesghana@tallyafrica.com";
    $subject = "PRODUCT AND SERVICE REQUEST";

    //from post form
    $user_name = $_POST['user_name'];
    $contact = $_POST['contact'];
    $email = $_POST['email'];
    $company_name = $_POST['company_name'];
    $company_address = $_POST['company_address'];
    $user_type = $_POST['user_type'];
    $pref_service_one = $_POST['pref_service_one'];
    $pref_service_one = $_POST['pref_service_two'];
    $addon_one = $_POST['addon_one'];
    $addon_two = $_POST['addon_two'];
    $comments = $_POST['comments'];

    $message = "NAME: " . $user_name . "\n\n" . "CONTACT: " . $contact . "\n\n" . "EMAIL: " . $email . "\n\n" . "COMPANY NAME: " . $company_name . "\n\n" . "COMPANY ADDRESS: " . $company_address . "\n\n" . "TALLY SOFTWARE: " . $user_type . "\n\n" . "PREFERRED SERVICE ONE: " . $pref_service_one . "\n\n" . "PREFERRED SERVICE TWO: " . $pref_service_two . "\n\n" . "ADDON ONE: " . $addon_one . "\n\n" . "ADDON TWO: " . $addon_two . "\n\n" . "COMMENTS: " . $comments;

    $headers = "<From: noreply@tallyafrica.com>";
    mail($to, $subject, $message, $headers);

    // added exit for safety in case there is more code below the if statement.
    exit();
}

或旧方法,但有错误报告:

// add in error reporting
ini_set('display_errors', 'On');
ini_set('html_errors', 0);
error_reporting(-1);

if (isset($_POST) && !empty($_POST))
{
    //pre-defined vals
    $to = "salesghana@tallyafrica.com";
    $subject = "PRODUCT AND SERVICE REQUEST";

    //from post form
    $user_name = $_POST['user_name'];
    $contact = $_POST['contact'];
    $email = $_POST['email'];
    $company_name = $_POST['company_name'];
    $company_address = $_POST['company_address'];
    $user_type = $_POST['user_type'];
    $pref_service_one = $_POST['pref_service_one'];
    $pref_service_one = $_POST['pref_service_two'];
    $addon_one = $_POST['addon_one'];
    $addon_two = $_POST['addon_two'];
    $comments = $_POST['comments'];

    $message = "NAME: " . $user_name . "\n\n" . "CONTACT: " . $contact . "\n\n" . "EMAIL: " . $email . "\n\n" . "COMPANY NAME: " . $company_name . "\n\n" . "COMPANY ADDRESS: " . $company_address . "\n\n" . "TALLY SOFTWARE: " . $user_type . "\n\n" . "PREFERRED SERVICE ONE: " . $pref_service_one . "\n\n" . "PREFERRED SERVICE TWO: " . $pref_service_two . "\n\n" . "ADDON ONE: " . $addon_one . "\n\n" . "ADDON TWO: " . $addon_two . "\n\n" . "COMMENTS: " . $comments;

    $headers = "<From: noreply@tallyafrica.com>";
    mail($to, $subject, $message, $headers);

    header("Location:http://www.prymage.com/thankyou.html");
    // added exit for safety in case there is more code below the if statement.
    exit();
}