简体   繁体   中英

sending email using php

I am working on a drupal site.I add a mail functionality to that site using php mail function and I used mozilla thunderberd for finding that email sending work properly.some time mailing is work correctly.but sometime it is not working at all without changing the code anyway.below is the code I used for sending email.

 $success = mail('lakshman@codegen.net','hi',$message);
            if($success){
                print "email send successfully";
            }else{
                print "email sending failed";   
            }

I used ajax reqest to fire this mail function using mootools.here is the code for that

$('emailButton').addEvent('click', function(event) {
    alert("hi I am here");
    event.stop();
    var hello = 'hello world.......!';
    var req = new Request({
            method: 'post',
            url: 'mail.php',
            data: { 'hello' : hello },
            onRequest: function() { alert('The request has been made, please wait until it has finished.'); },
            onComplete: function(response) { alert('The response is the following : ' + response); }
                }).send();
            });

is there any reason for that not working and working for same code?

You can add header in mail() .. like this

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $sFrom <ADMIN MAIL ID>\r\n";
$headers .= "To: $to\r\n";

header is not included in your mail function that can be reason that sometimes it gives an warning or errors...

You should usedrupal_mail function, as it takes care of headers for you.

PS : also, it is best practices to use Drupal's built-in jQuery behaviors .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM