[英]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無論如何代碼。下面是我用於發送 email 的代碼。
$success = mail('lakshman@codegen.net','hi',$message);
if($success){
print "email send successfully";
}else{
print "email sending failed";
}
我使用 ajax 請求使用 mootools 發送此郵件 function。這里是代碼
$('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();
});
有什么理由不工作和工作相同的代碼?
您可以在mail()
中添加 header .. 像這樣
$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 未包含在您的郵件 function 中,這可能是有時它會發出警告或錯誤的原因...
您應該使用drupal_mail function,因為它會為您處理標題。
PS:此外,使用Drupal 的內置 jQuery 行為是最佳實踐。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.