2016-03-26 25 views
-1

PHPMailer'in form verisinden posta göndermek için çalışmasına çalışıyorum (açıkçası).PHPMailer boş sayfaya gönderiyor

SAYI:

formu göndererek, ben boş bir sayfaya gönderilir alıyorum. Hata bildirilmiyor. Bu sorunu çözebildiğim kadar çok stackoverflow iş parçacığını takip ettim ve bu ileti dizilerindeki hiçbir çözüm bu sorunu kendim çözmedi.

Teşekkür

HATALAR:

kenara tüm hataları Sabit: 2016/03/26 22:10:43 SMTP ERROR: sunucuya bağlanamadı: Bağlantı (111) 2016-03-26 reddetti 22:10:43 SMTP connect() başarısız oldu. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

PHP:

<?php 
$message= 
'First Name: '.$_POST['first'].'<br /> 
Last Name: '.$_POST['last'].'<br /> 
Phone: '.$_POST['phone'].'<br /> 
Email: '.$_POST['email'].'<br /> 
Message: '.$_POST['message'].' 
'; 

require 'PHPMailer/PHPMailerAutoload.php'; 

    $mail = new PHPMailer(); 

    $mail->SMTPDebug = 2;   // Enable verbose debug output 
    $mail->IsSMTP();    // Sets up a SMTP connection 
    $mail->CharSet = 'UTF-8'; 
    $mail->SMTPAuth = true;   // Connection with the SMTP does require authorization  
    $mail->SMTPSecure = "tls";  // Connect using a TLS connection 
    $mail->Host = "smtp.gmail.com"; //Gmail SMTP server address 
    $mail->Port = 587; 

    // Authentication 
    $mail->Username = "[email protected]"; // Your full Gmail address 
    $mail->Password = "xxxx"; // Your Gmail password 

    // Compose 
    $mail->SetFrom($_POST['email'], $_POST['firstname'] . ' ' . $_POST['lastname']); 
    $mail->AddReplyTo($_POST['email'], $_POST['firstname'] . ' ' . $_POST['lastname']); 
    $mail->Subject = "New Contact Form Enquiry";  // Subject (which isn't required) 
    $mail->MsgHTML($message); 

    // Send To 
    $mail->AddAddress("[email protected]", "xxxx"); // Where to send it - Recipient 
    $result = $mail->Send();  // Send! 
    $message = $result ? 'Successfully Sent!' : 'Sending Failed!';  
    unset($mail); 
} 
?> 

HTML:

<form class="form-inline" name="contactform" action="mailer.php" enctype="multipart/form-data" method="POST"> 
        <div class="col-sm-6 form-group form-sty"> 
         <label class="sr-only" for="first" required>First Name</label> 
         <input type="text" class="form-control-sty" name="first" placeholder="First Name"> 
        </div> 
        <div class="col-sm-6 form-group form-sty"> 
         <label class="sr-only" for="last" required>Last Name</label> 
         <input type="text" class="form-control-sty" name="last" placeholder="Last Name"> 
        </div> 
        <div class="col-sm-6 form-group form-sty"> 
         <label class="sr-only" for="phone" required>Phone</label> 
         <input type="text" class="form-control-sty" name="phone" placeholder="Phone"> 
        </div> 
        <div class="col-sm-6 form-group form-sty"> 
         <label class="sr-only" for="email" required>Email</label> 
         <input type="email" class="form-control-sty" name="mailfrom" placeholder="Email"> 
        </div> 
        <div class="col-sm-12 form-sty"> 
         <label class="sr-only" for="comment">Comment</label> 
         <textarea class="form-control-sty" name="message" id="message" rows="7" placeholder="What's on your mind?" required></textarea> 
        </div> 
        <div class="col-sm-12 form-sty form-sty-btn"> 
         <button type="submit" value="Submit" class="btn btn-default col-sm-12">Send</button> 
        </div> 
        <p><?php if(!empty($message)) echo $message; ?></p> 
       </form> 
+1

Sen bir olduğunu söylemek senin URL ile başlığı içinde yerini değiştirin (Ben onları göndermek istediğiniz nerede olduğunu varsayalım) geri başlığı yönlendirmesi gerekir Sorun ve sonra sorun nedir * deme *. Hangi hataları/uyarıları alıyorsunuz? Kötü biçimlendirilmiş bir kodun duvarını gönderirseniz size nasıl yardımcı olabiliriz? –

+0

Lütfen memnun ve editoryal ile dağıtın. Sadece ilgili kodu ekleyin ve sorunu açıkça belirtin. – j08691

+0

Üzgünüm, Başlıkta. Sorun, gönderildikten sonra PHPMailer beni boş bir sayfaya gönderiyor. Hata alıyorum, boş sayfaya gidiyor. – dbrree

cevap

1

formun

<?php 
$message= 
'First Name: '.$_POST['first'].'<br /> 
Last Name: '.$_POST['last'].'<br /> 
Phone: '.$_POST['phone'].'<br /> 
Email: '.$_POST['email'].'<br /> 
Message: '.$_POST['message'].' 
'; 

require 'PHPMailer/PHPMailerAutoload.php'; 

    $mail = new PHPMailer(); 

    $mail->SMTPDebug = 2;   // Enable verbose debug output 
    $mail->IsSMTP();    // Sets up a SMTP connection 
    $mail->CharSet = 'UTF-8'; 
    $mail->SMTPAuth = true;   // Connection with the SMTP does require authorization  
    $mail->SMTPSecure = "tls";  // Connect using a TLS connection 
    $mail->Host = "smtp.gmail.com"; //Gmail SMTP server address 
    $mail->Port = 587; 

    // Authentication 
    $mail->Username = "[email protected]"; // Your full Gmail address 
    $mail->Password = "xxxx"; // Your Gmail password 

    // Compose 
    $mail->SetFrom($_POST['email'], $_POST['firstname'] . ' ' . $_POST['lastname']); 
    $mail->AddReplyTo($_POST['email'], $_POST['firstname'] . ' ' . $_POST['lastname']); 
    $mail->Subject = "New Contact Form Enquiry";  // Subject (which isn't required) 
    $mail->MsgHTML($message); 

    // Send To 
    $mail->AddAddress("[email protected]", "xxxx"); // Where to send it - Recipient 
    $result = $mail->Send();  // Send! 
    if ($result) 
    { 
     header("Location: : http://www.example.com/contactform.php"); 
    } 
    else { 
     echo "sending mail failed: " . $mail->ErrorInfo; 
    } 
    unset($mail); 
} 
?> 
+0

Bu aslında bana şu hatayı veriyor: Uyarı: Başlık bilgileri değiştirilemiyor - üstbilgiler (/home/xxxx/public_html/PHPMailer/class.smtp.php:234 adresinde zaten gönderilmiş olan)/home/xxxx/public_html/mailer.php on line 41 – dbrree

+1

Bir üstbilgi ayarlamadan önce herhangi bir çıktıyı ekleyemezsiniz. Bu nedenle, başlıktan önce hata ayıklama ekosunun bulunmadığından emin olun. – Torchify

+0

Bunu da çözdü. Ben SMTPDebug devre dışı bırakmak/yorumlamak zorunda kaldı ve o sadece iyi çalıştı. Yardım için teşekkürler. – dbrree

1

Sen hiç hata olmadığından emin olmak gerekir. Tüm hataları/uyarıların bildirildiğinden ve komut dosyasını yeniden çalıştırdığından emin olmak için bu kodu dosyanızın en üstüne yerleştirmeyi deneyin.

ini_set('display_startup_errors',1); 
ini_set('display_errors',1); 
error_reporting(E_ALL); 
+0

Teşekkür ederim, hataları şimdi görebiliyorum. Bunu anlayamazsam gönderirim. – dbrree

+0

OP'de hata ekledim. – dbrree

+0

Tamamen şu hataları düzeltdim: 2016-03-26 22:10:43 \t SMTP HATASI: Sunucuya bağlanılamadı: Bağlantı reddedildi (111) 2016-03-26 22:10:43 \t SMTP connect() başarısız oldu . https://github.com/PHPMailer/PHPMailer/wiki/Sorun Giderme – dbrree