我在向我的收件箱(Gmail帐户)发送邮件时遇到问题,但是每次都转到垃圾邮件文件夹时。这是代码片段
//$ticketDetail is array which contain required information to send. sendOwnershipEmail('dineshnagarscriet@gmail.com', $ticketDetail); function sendOwnershipEmail($email, $ticketDetail) { $param = new stdClass(); $param->content = "<div> <div><b>".$ticketDetail[0]['ticket_number']."</b></div><br/> <div><img src='".$ticketDetail[0]['image_path']."'/></div><br/> <div>Ticket with ticket number ".$ticketDetail[0]['ticket_number']." has been requested for tranfer from <div/> <div>".$ticketDetail[0]['oldDepartment']." to ".$ticketDetail[0]['newDepartment']." Department <div/> </div>"; $param->sendTo = $email; $param->subject = "Request for Department transfer"; sendMailFunction($param); } function sendMailFunction($param) { $to = $param->sendTo; $subject = $param->subject; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: successive.testing@gmail.com' . "\r\n"; $message = "<html><head>" . "<meta http-equiv='Content-Language' content='en-us'>" . "<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>" . "</head><body>" .$param->content. "<br><br></body></html>"; mail($to, $subject, $message, $headers); }
我尝试过很多类似将标头设置为Reply-To,Return-Path等的方法,但是每次都将其转为垃圾邮件时。你能找出问题所在吗?
问题很简单,PHP-Mail功能没有使用配置良好的SMTP服务器。
如今,电子邮件客户端和服务器会对电子邮件发送服务器进行大量检查,例如反向DNS查找,灰名单和whatevs。所有这些测试都将因php mail()函数而失败。如果您使用的是动态IP,那就更糟了。
使用PHPMailer-Class并将其配置为使用smtp-auth以及配置良好的专用SMTP服务器(本地或远程SMTP服务器),您的问题就消除了。