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.....开发者_Go百科..!';
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 use drupal_mail function, as it takes care of headers for you.
P.S. : also, it is best practices to use Drupal's built-in jQuery behaviors.
精彩评论