2016-03-27 16 views
0
<?php 
//if "email" variable is filled out, send email 
if (isset($_REQUEST['email'])) { 

    //Email information 
    $admin_email = "[email protected]"; 
    $email = $_REQUEST['email']; 
    $subject = $_REQUEST['subject']; 
    $comment = $_REQUEST['comment']; 

    //send email 
    mail($admin_email, "$subject", $comment, "From:" . $email); 

    //Email response 
    echo "Thank you for contacting us!"; 
} 
//if "email" variable is not filled out, display the form 
else { 
?> 

<form method="post"> 
    <input name="email" type="text" class="form-control" placeholder="Enter your email address..."> 
    <input name="subject" type="text" class="form-control" placeholder="Subject"> 
    <br> 
    <textarea name="comment" class="form-control" rows="3"></textarea> 
    <br> 
    <div class="mesbutts"> 
     <button type="submit" class="btn btn-primary" value="Submit">Send</button> 
     <button type="reset" value="Reset" class="btn btn-default" >Clear</button> 
    </div> 

</form> 
<?php 
} 
?> 

Merhaba arkadaşlar, PHP kodumu form kullanarak bir e-posta göndermek için nasıl çalıştırabilirim anlayamıyorum. Kişisel e-postalarımı çoktan ekledim ve onları göremiyorum. Sözdizimdeki hatayı bulmama yardım edebilir misin?PHP'de form türü html ile bir e-posta gönderiliyor

Teşekkür ederim dostum!

+0

Content-type' manuel http://php.net/manual/en/function.mail.php – Naumov

+0

Olası yinelenen içinde size görev için örnek numarasını 4 kilitlemek fonksiyonu posta başlığını kullanıp 'set ihtiyaç [PHP posta formu e-posta göndermeyi tamamlamıyor] (http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – Qirel

+0

hi @Naumov tam olarak nasıl yapabilirsiniz? yap bunu? Üzgünüz, –

cevap

1

Bu size yardımcı olduğunu düşünüyorum. Ancak php, örneğin phpMailer veya kütüphane üzerinden e-posta göndermek için kütüphaneyi kullanmanın daha iyi bir yolu.

<?php 
//if "email" variable is filled out, send email 
if (isset($_REQUEST['email'])) { 
    $headers = 'MIME-Version: 1.0' . "\r\n"; // set mime version 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // set content-type as html 
    //Email information 
    $admin_email = "[email protected]"; 
    $email = $_REQUEST['email']; 
    $subject = $_REQUEST['subject']; 
    $comment = $_REQUEST['comment']; 

    //send email 
    mail($admin_email, "$subject", $comment, "From:" . $email,$headers); // adding headers to mail 

    //Email response 
    echo "Thank you for contacting us!"; 
} 
//if "email" variable is not filled out, display the form 
else { 
?> 

<form method="post"> 
    <input name="email" type="text" class="form-control" placeholder="Enter your email address..."> 
    <input name="subject" type="text" class="form-control" placeholder="Subject"> 
    <br> 
    <textarea name="comment" class="form-control" rows="3"></textarea> 
    <br> 
    <div class="mesbutts"> 
     <button type="submit" class="btn btn-primary" value="Submit">Send</button> 
     <button type="reset" value="Reset" class="btn btn-default" >Clear</button> 
    </div> 

</form> 
<?php 
} 
?> 
+0

numaralı telefondan noob bir e-posta alıyorum. Html başlığına bir şey koymam gerekiyor mu? Yoksa web sitemi ilk önce mi barındırmam gerekiyor? –

+0

Site, localhost'a yükleniyor? sunucu (localserver) ayarlamamışsanız (postfix, sendmail) veya e-posta göndermek için başvuruda bulunmuyorsa, web sitenizi barındırabilirsiniz. – Naumov