Phpmailler Post方法不起作用

时间:2016-02-17 14:25:03

标签: php html post

我尝试提交联系表单时有php网站Post方法无效。 index.html中的所有表单元素都将与您共享代码。如果你能帮助我,我会很高兴的

在HTML文件(index.php)

            <form id="main-contact-form"  method="post" action="sendemail.php">
              <div class="form-group">
                <input type="text" name="name" class="form-control"  placeholder="İsim Soyisim" required>
              </div>
              <div class="form-group">
                <input type="email" name="mail_adress" class="form-control" placeholder="Mail Adresi" required>
              </div>
              <div class="form-group">
                <input type="text" name="subject" class="form-control" placeholder="Konu" required>
              </div>
              <div class="form-group">
                <textarea  class="form-control" name="message" rows="8" placeholder="Mesaj" required></textarea>
              </div>
              <button type="submit" name="send" class="btn btn-primary">Mesaj Gönder</button>
            </form>
PHP中的

(sendemail.php)

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';                       // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'xx@xxxxx.com';                   // SMTP username
$mail->Password = 'xxxxx';               // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
$mail->Port = 587;                                    //Set the SMTP port number - 587 for authenticated TLS
$mail->setFrom('xxx@xxxxxx.com', 'xx xx xx');     //Set who the message is to be sent from

$mail->addAddress('xxx@xxxxx.com', 'xx xx xx xx');  // Add a recipient
$mail->WordWrap = 50;                                 // Set word wrap to 50 characters

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $_POST['subject'];
$mail->Body    = 'Mesaj Konusu'.$_POST['name'];
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body


if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   echo $_POST['subject'];
   exit;
}

echo 'Message has been sent';



 ?>

谢谢

4 个答案:

答案 0 :(得分:0)

尝试与=== operador进行比较,不仅要比较相同的值,还要比较相同的数据类型。

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // …
}

答案 1 :(得分:0)

当我确定everthings变得很好时,我发现答案ajax阻止POST方法

var form = $('#main-contact1-form');
    form.submit(function(event){
        event.preventDefault();
        var form_status = $('<div class="form_status"></div>');
        $.ajax({
            url: $(this).attr('action'),
            beforeSend: function(){
                form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Mail Gönderiliyor...</p>').fadeIn() );
            }
        }).done(function(data){
            form_status.html('<p class="text-success">Mesajınız başarı ile iletilmiştir. En kısa sürede tarafınıza dönüş yapılacaktır.</p>').delay(3000).fadeOut();
        });
    });

当我删除此代码时,每个人都很好。如何修复它而不删除它..?这是一个值得提问的新问题......

答案 2 :(得分:0)

    <?php
function sendmail($to,$subject,$message,$from)
{

//如果我们的任何行都超过70个字符,我们应该使用wordwrap()

$message = wordwrap($message, 70, "\r\n");
$headers = "From: $from" . "\r\n" .
    "Reply-To: $from" . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    $headers = "From: " . $from. "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail($to, $subject, $message, $headers);
}
?>

答案 3 :(得分:-1)

  

你写== POST(大写字母),并使用method = post(小写字母),所以在两个地方都将它改为小或大写。或者检查sendmail.php