在垃圾邮件中转发电子邮件

时间:2018-12-15 06:08:42

标签: cakephp gmail sendgrid email-spam amazon-ses

我在CakePHP中有一个项目,正在其中开发一个API并在此API内。我正在使用电子邮件功能,但是每当我运行该功能时,它都会在垃圾邮件文件夹中发送邮件。我曾尝试使用其他电子邮件服务提供商(例如AWS,sendgrid,Gmail),但每次将我的邮件转发到垃圾邮件文件夹中时,都无法使用。 这是我的控制器的代码段,描述了电子邮件功能

$password= $this->randomPassword();                          
$message = 'this is a test mail from gmail.';
$email    = new Email('default'); 
$email->transport('gmail');
$to       = $user_info['email'];
$subject  = 'Forgot Password';
$headers  = 'From: sender_address' . "\r\n" . 
            'MIME-Version: 1.0\r\n' .
            'Content-type: text/html; charset=utf-8'.
            'X-Priority: 3'.
            'X-Mailer: PHP/' . phpversion(); 
mail($to, $subject, $message, $headers);

这是我在应用程序配置文件中的电子邮件传输器:

'EmailTransport' => [
    'default' => [
        'className' => 'Mail',
        // The following keys are used in SMTP transports
        'host' => 'my-webmail_ip',
        'port' => 465,
        'timeout' => 30,
        'username' => 'username',
        'password' => 'password',
        'client' => null,
        'tls' => null,
        'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
    ],

     'sendgrid' => [
        'className' => 'Mail',
        // The following keys are used in SMTP transports
        'host' => 'smtp.sendgrid.net',
        'port' => 587,
        'timeout' => 30,
        'username' => 'apikey',
        'password' => 'api_key_of_sendgrid',
        'client' => null,
        'tls' => null,
    ] 
    'ses' => [
        'className' => 'Smtp',
        'host' => 'email-smtp.us-east-1.amazonaws.com',
        'port' => 587,
        'username' => 'username',
        'password' => 'password',
        'tls' => true
    ],
    'gmail' => [
        'className' => 'Smtp',
        'host' => 'ssl://smtp.gmail.com',
        'port' => 587,
        'username' => 'username',
        'password' => 'password',
        'tls' => true
    ],
],

'Email' => [
     'default' => [
        'transport' => 'default',
        'from' => 'you@localhost',
        'charset' => 'utf-8',
        'headerCharset' => 'utf-8',
    ], 
    'default' => [
        'transport' => 'ses',
        'from' => 'you@localhost',    
    ],
    'default' => [
        'transport' => 'gmail',
        'from' => 'you@localhost',    
    ],
],

我已经尝试了所有这些电子邮件提供商,但是没有一个人正在收件箱中发送。即使电子邮件与每个电子邮件都兼容。如果有人曾经有过这种经验,请让我知道解决方案或调试此问题的方法。会非常感激的。

0 个答案:

没有答案