JQuery / PHP ile e-posta gönderme

2 Cevap php

How can you send an email by jQuery and PHP if the user flags a question?

My JS code in HEAD

jQuery('a.flag_question').live('click', function(){
    jQuery.post('/codes/handlers/flag_question.php', 
        { question_id: jQuery(this).attr('rel') });                                            
            alert ("Question was reported.");
});

Its handler flag_question.php which does not send me an email

$question_id = $_POST['question_id'];   // data from jQuery.post
$subject = "Flagged question"; 
$to = '"Michael Boltman <michael.boltman777@gmail.com>';
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

$message = "<a href='index.php?question_id=" . $question_id . "'>"
    . "The question " . $question_id . "</a> is flagged by an user. Please, review it.";
if ( mail( $to, $subject, $message ) ) {
    echo ("Thank you for your report!");

}

Kodunda bir sahte biri iken ben, benim gerçek e-posta adresini kullanabilirsiniz yaptım.

The link is generated by PHP

    echo ("<a href='#'"
            . " class='flag_question'"
            . " rel='" . $question_id . "'>flag</a>"
        );

2 Cevap

You can checkout the documentation for php's mail function here.

Item of note: Bu fonksiyon genellikle sunucu / sistem doğru şekilde yapılandırılmış değilse çalışmaz gibi görünüyor, çünkü belgeleri açıklamalar, geçici çözümleri ilanıyla pek çok insan vardır.

Bu, kullanıcıların açıklama yararlı olabilir (link)

Edward 01-Aug-2009 09:08

Şu anda benim barındırma hizmeti Godaddy üzerinde. "-F" içeren beşinci parametre olmadan posta işlevini kullanmak için çalışırken, benim mesaj başlıklarını işe yaramaz.

Mesaj başlıklarını işe yaramazsa zaman, sadece beşinci parametresi kullanmayı deneyin:

<?php
mail($to, $subject, $message, $headers, "-femail.address@example.com");
?>

PHP'nin için çağrı mail function seems to send mail to test@gmail.com. Bu gerçek e-posta adresi ise ben aksi takdirde gerçek e-posta adresinizi kullanmak gerekir, etkilendim olacaktır. Eğer olsaydı, bu belirtin.

Kontrol Şeyler:

  • Gmail posta spam olduğunu düşünüyor olmadığını görmek için gmail üzerinde "spam" klasörünü kontrol edin. Eğer öyleyse, birçok soru SO bunun cevabı "How do I make sure my email isn't considered spam?" burada var
  • Bu posta PHP komut kabul ve düzgün Gmail'e teslim edilmiştir raporları olup olmadığını görmek için (sizin Ubuntu kutusuna çalışan ne olursa olsun) yerel MTA kontrol edin. Bu sorunu ise, o serverfault.com bu sorunu teşhis için doğru yerdir.