PHP脚本是正确的,但不发送

时间:2016-07-30 01:11:04

标签: php contact-form

我的PHP代码有困难。从我疲惫的眼神中,代码是正确的,我已经有多个其他人看了代码。没有人能弄清楚它为什么不起作用。它必须是非常简单的东西,但我无法通过联系表单发送。

PHP脚本:

<?php


$from = 'email@example.com';
$sendTo = 'email@example.com';
$subject = 'New message from contact form';
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message');
$htmlHeader = '';
$htmlFooter = '';
$okMessage = 'Contact form succesfully submitted. Thank you, We will get back to you soon!';

$htmlContent = '<h1>New message from contact form</h1>';



use Nette\Mail\Message,
    Nette\Mail\SendmailMailer;


require 'php/Nette/nette.phar';


$configurator = new Nette\Configurator;
$configurator->setTempDirectory(__DIR__ . '/php/temp');
$container = $configurator->createContainer();


$httpRequest = $container->getService('httpRequest');
$httpResponse = $container->getService('httpResponse');

$post = $httpRequest->getPost();

if ($httpRequest->isAjax()) {

    $htmlContent .= '<table>';
    foreach ($post as $key => $value) {

    if (isset($fields[$key])) {
        $htmlContent .= "<tr><th>$fields[$key]</th><td>$value</td></tr>";
    }
    }
    $htmlContent .= '</table>';


    $htmlBody = $htmlHeader . $htmlContent . $htmlFooter;


    $mail = new Message;
    $mail->setFrom($from)
        ->addTo($sendTo)
        ->setSubject($subject)
        ->setHtmlBody($htmlBody, FALSE);

    $mailer = new SendmailMailer;
    $mailer->send($mail);


    $responseArray = array('type' => 'success', 'message' => $okMessage);

    $httpResponse->setCode(200);
    $response = new \Nette\Application\Responses\JsonResponse($responseArray);
    $response->send($httpRequest, $httpResponse);
}

联系表单HTML:

<div class="section contact soepa" id="contact" data-animate="bounceIn">
    <div class="container">
        <div class="col-md-12">


            <h2 class="title"><span style="color: #f46b01;">Connect With Us</span></h2>

            <div class="row">

                <div class="col-md-8 col-md-offset-2">
                    <form id="contact-form" method="post" action="contact.php">

                        <div class="messages">

                        </div>

                        <div class="controls">

                            <div class="row">
                                <div class="col-md-6">
                                    <input type="text" name="name" class="form-control" placeholder="Your firstname *" required="required">
                                </div>
                                <div class="col-md-6">
                                    <input type="text" name="surname" class="form-control" placeholder="Your lastname *" required="required">
                                </div>
                                <div class="col-md-6">
                                    <input type="text" name="email" class="form-control" placeholder="Your email *" required="required">
                                </div>
                                <div class="col-md-6">
                                    <input type="text" name="phone" class="form-control" placeholder="Your phone *" required="required">
                                </div>

                                <div class="col-md-12">
                                    <textarea name="message" class="form-control" placeholder="Message *" rows="4" required="required"></textarea>
                                </div>
                                <div class="col-md-12 text-center">
                                    <input type="submit" class="btn btn-primary btn-lg" value="Send message">
                                </div>
                            </div>
                        </div>

                    </form>
                </div>

            </div>

        </div>
    </div>
</div>

0 个答案:

没有答案