Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

php - mail delivered as spam - phpmailer, how to avoid

I know that in first look many users mark this question as duplicate, but after reading more than 10 question I did not get any satisfactory answer, almost all question has answers having words like "There's not much you can do about it.", "I am not sure", "There is no sure shot trick" etc. that's why I am writing this question, and I think this is very generalized questions and every php developer faces it at least once, ok enough speech :) , now my question is..

I working on a project management application and am using phpmailer to send mail when any task is created or anybody comments on any bug mails are sent to related users, actually instead of sending mails as soon the action happens I have created a 'notifications' table where I actually save all mail data and a cron script then send all mails, here is some part of my cron script.

$query = "select * from notifications where  1 ";
    $projects = $obj_basic->get_query_data($query);  

    if(!empty($projects))
    {
        foreach($projects as $data)
        {       
            $message = html_entity_decode($data['content'], ENT_QUOTES);            
            list($ton, $email) =  get_name_email($data['to']);      

            if(!empty($email))
            {
                $query = "select send_notification from users where email='$email' AND send_notification !='1' ";
                $users = $obj_basic->get_query_data($query);
                if(!empty($users))
                {
                    $deleteQuery = "delete from notifications where id ='".$data['id']."'";
                    $obj_basic->run_query($deleteQuery, 'DELETE');
                    continue;
                }

                $comment_id = $data['reference_id'];
                $attribute = $data['attribute'];
                $mail = new PHPMailer();
                list($fromName, $fromEmail) =  get_name_email($data['from']);       
                if(!empty($comment_id) && $attribute == 'comment')
                {
                    $fromEmail = 'comment@changewebaddress.com';
                }

                $mail->SetFrom($fromEmail, $fromName);
                $mail->AddReplyTo($fromEmail, $fromName);
                $mail->AddAddress($email, $ton);
                $mail->BouncedTo = $fromEmail;
                $mail->IsHTML(true);                               
                $mail->Subject  = $data['subject'];              
                $mail->Body =  $message;        
                $MessageID = "<".md5($comment_id.'_'.$email).'@changewebaddress.com>';
                $mail->MessageID= $MessageID;

                if($mail->Send()) {         
                    if(!empty($comment_id) && $attribute == 'comment')
                    {
                        $query = "SELECT message_id FROM `project_comments` WHERE `id`='$comment_id'; ";
                        $project_comments = $obj_basic->get_query_data($query, 'SELECT');

                        if(!empty($project_comments))
                        {
                            $project_comments[0]['message_id'] = html_entity_decode(trim($project_comments[0]['message_id'], ","));
                            $query = "UPDATE  `project_comments` SET `message_id`=CONCAT_WS(',',  '".mysql_escape_string($project_comments[0]['message_id'])."', '".mysql_escape_string(html_entity_decode($MessageID))."') WHERE `id`='$comment_id'; ";
                            $obj_basic->run_query($query, 'UPDATE');
                        }                       
                    }                   
                    $deleteQuery = "delete from notifications where id ='".$data['id']."'"; 
                    $obj_basic->run_query($deleteQuery, 'DELETE'); 
                }           
            }
        }
    }

as per what I have tested everything look good, since I am using phpmailer it sets required header it also sets 'Return-Path:' and 'Reply-To:' in header.

Is there any exact solution on this issue

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Make sure all of the required headers are being set.
  2. Check to see if there are any additional, optional headers that you should be setting.
  3. Sending an HTML/multipart message with mismatched text/HTML sections is frowned upon by some filters.
  4. Absolutely any mail that you send programmatically should have either a link or instructions on how to opt out. This is usually only enforced by human-curated blacklists and the abuse department at your ISP.
  5. Make sure your SMTP server is not blacklisted or has a poor reputation.
  6. Make sure your web server does not have a poor reputation. Some scanners include the reputation of every MTA in the chain.
  7. Review the content of your messages before sending them. If anything in it could even roughly be construed as trying to sell something to someone, change it.
  8. Sacrifice a small animal to the dark gods of email and hope against hope.
  9. Check the headers of the messages marked as spam to see if the spam filtering system left any useful information about why it was blocked.
  10. Ask the receiving server's admins why the message was blocked.
  11. Accept that there is no, and never will be an "exact solution on this issue". Ever.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...