简体   繁体   中英

Sent email appears in recipient's spam folder in cakePHP using gmail account?

I am Using cakephp for one of my project. for sending email I am using cakeEmail. For that I created one gmail account for sending emails(ie used in code for send mail from that account).Mail sending works but sent mail appears recipient's spam folder.
Also in gmail account that mail dosen't appear sent mail folder.

code is as bellow :

In /app/Config/email.php file is :

class EmailConfig {

    public $gmail = array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'username@gmail.com',
        'password' => 'password',
        'transport' => 'Smtp'
    );  

}

and code in my controller file for password recovery is :

public function _sendemail($user_data,$temporary_password){

            $email = new CakeEmail();
            $email->config('gmail');
            $email->template('welcome', 'password_recovery_email'); //template
            $email->emailFormat('html');
            $email->viewVars(array(
                               'temporary_password'=>$temporary_password,
                               'user_data'=>$user_data
                            ));
            $email->from(array('username@gmail.com' => 'Password Recovery'));
            $email->to($user_data['User']['email_address']);

            $email->subject('password recovery email');

            $result=$email->send();



    }

Please tell me what should I do to get all sent emails to appears in inbox rather than spam folder.

Thanks

A lot of reasons can make your email be considered a SPAM.

  • Maybe Gmail can't check the sender (smtp source/your developing machine) as a trusted sender. Have you tried uploading your php script to another server (production) then sending it from there?

  • Have you tried changing the message content/subject to something different from "Recover your password"?

  • Have you tried sending the same message to another recipient?

Gmail uses a lot of rules to check whether an email is a spam or not, check out this link: https://webapps.stackexchange.com/questions/5773/how-gmail-and-other-mail-services-detects-a-mail-as-a-spam

Try using this code rather than cakephp's methods:

     $subject = "Your Email Subject";
     $to = "Recipient's Email Address";
     $from = "Your Email Address";
     $additional_headers = "From: $from\r\n";
     $additional_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
     $additional_headers .= "MIME-Version: 1.0\r\n";
     $additional_headers .= "Return-Path: $from\r\n";
     $additional_headers .= "X-Priority: 3\r\n";
     $additional_headers .= "X-Mailer: PHP\r\n";
     $message = "Your Email Body";
     mail($to, $subject, $message, $additional_headers, "-f $from")

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