1

I'm trying to make php contact form work on webhost we are currently using. I found with google this trick to get it work when smtp is off:
http://www.top-answers.net/webhost/web-hosting.html
What I found it only gives me white screen on browser when I upload it to server but as offline it shows the form correctly. Is there way to make this work or should I seek for another solution?

Thank you

<?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 } ?>
Mr O
  • 33
  • 6
  • You are using pear package to load your mail dependency. Your hosting environment might not be correctly configured for this. A better would be to use composer to include your mail dependency to send mail. – Hyder B. Apr 01 '17 at 08:34
  • Possible duplicate of [How to get useful error messages in PHP?](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) – user3942918 Apr 01 '17 at 15:18

0 Answers0