[英]php mailer redirect to blank page after clicking on send button
我只想知道我的實例是什么原因。
我的代碼如下所示:
<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');
我真的很困惑,我嘗試了一切,但仍然沒有任何成功。 我的托管也沒有告訴我有關此問題的任何信息。 我嘗試使用發送郵件功能,但情況是一樣的。
我將不勝感激任何答案。
我認為你被 header() 函數的濫用所困擾。 從手冊
請記住,必須在發送任何實際輸出之前調用 header(),無論是通過普通的 HTML 標記、文件中的空行還是來自 PHP。 使用 include 或 require 函數或其他文件訪問函數讀取代碼,並且在調用 header() 之前輸出空格或空行,這是一個非常常見的錯誤。 使用單個 PHP/HTML 文件時存在同樣的問題。
諸如空行和您的echo
語句之類的事情,或者實際上,誰知道require
d 文件中發生了什么,都會導致您的調用以header
重定向失敗。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.