简体   繁体   English

单击发送按钮后,php邮件程序重定向到空白页面

[英]php mailer redirect to blank page after clicking on send button

I just want to know what is the reason of my instance.我只想知道我的实例是什么原因。

My code looks like this:我的代码如下所示:

<form action="php/contact.php" method="post" enctype="multipart/form-data">
                                <fieldset>
                                    <input type="hidden" name="action" value="contact_send" />

                                    <div class="row">
                                        <div class="col-md-6">
                                            <label for="contact:name">Full Name *</label>
                                            <input required type="text" value="" class="form-control" name="contact[name][required]" id="contact:name">
                                        </div>
                                        <div class="col-md-6">
                                            <label for="contact:email">E-mail Address *</label>
                                            <input required type="email" value="" class="form-control" name="contact[email][required]" id="contact:email">
                                        </div>
                                        <div class="col-md-12">
                                            <label for="contact:phone">Phone</label>
                                            <input type="text" value="" class="form-control" name="contact[phone]" id="contact:phone">
                                        </div>

                                        <div class="col-md-12">
                                            <label for="contact:subject">Subject *</label>
                                            <input required type="text" value="" class="form-control" name="contact[subject][required]" id="contact:subject">
                                        </div>

                                        <div class="col-md-12">
                                            <label for="contact:message">Message *</label>
                                            <textarea required maxlength="10000" rows="6" class="form-control" name="contact[message]" id="contact:message"></textarea>
                                        </div>
                                    </div>

                                </fieldset>

                                <div class="row">
                                    <div class="col-md-12">
                                        <button type="submit" class="btn btn-primary"><i class="fa fa-check"></i> SEND MESSAGE</button>
                                    </div>
                                </div>
                            </form>


<?php

date_default_timezone_set('America/Toronto');

require 'http://***.net/php/PHPMailerAutoload.php';

 $mail = new PHPMailer;


$mail->isSMTP();

$mail->SMTPDebug = 2;


$mail->Debugoutput = 'html';


$mail->Host = 'smtp.gmail.com';

 $mail->Host = gethostbyname('smtp.gmail.com');


submission
$mail->Port = 587;


$mail->SMTPSecure = 'tls';


$mail->SMTPAuth = true;


$mail->Username = "****@gmail.com";


$mail->Password = "****";

//Set who the message is to be sent from
$mail->setFrom('kontakt@****', '');

//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');

//Set who the message is to be sent to
$mail->addAddress('', 'John Doe');

//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';

//Read an HTML message body from an external file, convert referenced images                     
to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));

//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';

//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
$headers = 'From: '.$name."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
header('Location: http://***.net/kontakt.html');

I am really confused, I tried everything with that but still without any succes.我真的很困惑,我尝试了一切,但仍然没有任何成功。 My hosting also did not tell me anything about this problem.我的托管也没有告诉我有关此问题的任何信息。 I tried with send mail function but the case is the same.我尝试使用发送邮件功能,但情况是一样的。

I will be gratefull for any answer.我将不胜感激任何答案。

I think you're getting bitten by the misuse of the header() function.我认为你被 header() 函数的滥用所困扰。 From the manual手册

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.请记住,必须在发送任何实际输出之前调用 header(),无论是通过普通的 HTML 标记、文件中的空行还是来自 PHP。 It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called.使用 include 或 require 函数或其他文件访问函数读取代码,并且在调用 header() 之前输出空格或空行,这是一个非常常见的错误。 The same problem exists when using a single PHP/HTML file.使用单个 PHP/HTML 文件时存在同样的问题。

Things like blank lines and your echo statements, or indeed, who knows what goes on in the require d file, are causing your call to redirect with a header to fail.诸如空行和您的echo语句之类的事情,或者实际上,谁知道require d 文件中发生了什么,都会导致您的调用以header重定向失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM