为何联系表格在线时会显示空白屏幕?

时间:2017-04-01 08:26:12

标签: php smtp contact-form

我试图让我们正在使用的虚拟主机上的php联系表单工作。当smtp关闭时,我发现谷歌有这个技巧让它工作:
http://www.top-answers.net/webhost/web-hosting.html
我发现它只在浏览器上显示白屏时将其上传到服务器但在离线时它会正确显示表单。 有没有办法使这项工作或我应该寻求另一种解决方案?

谢谢

<?php

function has_header_injection($str) {
    return preg_match( "/[\r\n]/", $str );
}

if (isset ($_POST['contact_submit'])) {

    $name  = trim($_POST['name']);
    $company  = trim($_POST['company']);
    $email  = trim($_POST['email']);
    $phone  = trim($_POST['phone']);
    $msg  = $_POST['message'];

    if (has_header_injection($name) || has_header_injection($company) ||has_header_injection($email) ||has_header_injection($phone)) {
        die();
    }

    if ( !$name || !$company || !$email || !$phone || !$msg ) {
        echo '<h4 class="error">Kaikki kentät ovat pakollisia.</h4><a href="" class="button block">Palaa takaisin ja yritä uudelleen</a>';
        exit;
    }

    $to = "info@mydomain.com";

    $subject = "$name lähetti viestin lomakkeen kautta";

    $message  = "Nimi: $name\r\n";
    $message .= "Yritys: $company\r\n";
    $message .= "Sähköposti: $email\r\n";
    $message .= "Puhelin: $phone\r\n";
    $message .= "Viesti:\r\n$msg";

    if (isset($_POST['subscribe']) && $_POST['subscribe'] == 'Subscribe') {
        $message .= "\r\n\r\n$name tilasi uutiskirjeen. Muista lisätä sähköpostilistalle!\r\n";
    }

    $message = wordwrap($message, 72);

     require_once "Mail.php";
    $from = "info@mydomain.com";  \\the mail-iD under your domain
    $to = "myemail@myemail.com"; \\the TO gmail ID
    $subject = "PHP Enquiry form";
    $body = $email_message;
    $host = "mail.mydomain.com"; \\ your domain mail server
    $username = "info@mydomain.com";  \\the mail-id under your domain
    $password = "secretsecurepassword";    \\your password for yourid@mydomain.com
    $headers = array ('From' => $from, 'To' => $to, 'Reply-To'=> $email_from, 'Subject' => $subject); 
    $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
    $mail = $smtp->send($to, $headers, $body);

?>

<h5>Kiitos yhteydenotosta!</h5>
<p>Vastaamme kahden arkipäivän kuluessa.</p>

<?php } else { ?>

<form method="post" action="" id="contact">

<label for="name">Nimi</label>
<input type="text" id="name" name="name">

<label for="company">Yritys</label>
<input type="text" id="company" name="company">

<label for="email">Sähköposti</label>
<input type="email" id="email" name="email">

<label for="phone">Puhelin</label>
<input type="text" id="phone" name="phone">

<label for="message">Viesti</label>
<textarea id="message" name="message"></textarea>

<input type="checkbox" id="subscribe" name="subscribe" value="Subscribe">
<label for="subscribe">Tilaa uutiskirje</label>

<button type="submit" class="button next" name="contact_submit">Lähetä</button>

</form>

<?php } ?>

0 个答案:

没有答案