SMTP на CodeIgniter показывает успех, но электронная почта не доставляется в аккаунт Gmail - программирование
Подтвердить что ты не робот

SMTP на CodeIgniter показывает успех, но электронная почта не доставляется в аккаунт Gmail

Я пытаюсь настроить SMTP на CodeIgniter. Все работает нормально, и я получаю сообщение о успехе на странице, что письмо отправляется без ошибок. Но электронная почта не доставлена.

Вот код, который я использую:

$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]', 
'smtp_pass' => '***', 
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);

$this->email->from('[email protected]', 'Explendid Videos');
$this->email->to('[email protected]');
$this->email->reply_to('[email protected]', 'Explendid Videos');


$this->email->subject('Explendid Video - Contact form');

$message = "Contact form\n\n";
$message .= "Name: ". $_POST['name'] . "\n";
$message .= "Phone: ". $_POST['phone'] . "\n";
$message .= "Email: ". $_POST['email'] . "\n";

$this->email->message($message);

$this->email->send();

Что может быть причиной того, что электронная почта на самом деле не доставлена.

4b9b3361

Ответ 1

Измените его на следующее:

$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "[email protected]"; 
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";

$ci->email->initialize($config);

$ci->email->from('[email protected]', 'Blabla');
$list = array('[email protected]');
$ci->email->to($list);
$this->email->reply_to('[email protected]', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();

Ответ 2

вот работа для меня на сервере apache2, ci 2.1.4: ее очень просто: сначала создайте файл под названием email.php в вашем каталоге application/config, затем введите следующий код внутри них: →

<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'u'r gmail account';
$config['smtp_pass'] = 'password of u'r account';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
?>

затем создайте файл под названием email.php под вашим каталогом приложений/контроллеров, затем введите этот код ~ >

    <?php
    class Email extends CI_Controller
    {

    function send()
    {
    // Loads the email library
    $this->load->library('email');
    // FCPATH refers to the CodeIgniter install directory
    // Specifying a file to be attached with the email
    // if u wish attach a file uncomment the script bellow:
    //$file = FCPATH . 'yourfilename.txt';
    // Defines the email details
    $this->email->from('[email protected]', 'ur Name');
    $this->email->to('[email protected]');
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');
    //also this script
    //$this->email->attach($file);
    // The email->send() statement will return a true or false
    // If true, the email will be sent
    if ($this->email->send()) {
    echo "you are luck!";
    } else {
    echo $this->email->print_debugger();
    }
    }

    }
    ?>

Ответ 3

заменить

$config['protocol'] = 'smtp';

к

$config['protocol'] = 'sendmail';

Ответ 4

Вы проверили файл php.ini? Попробуй. Если нет, возможно, вы также можете попробовать SPF. SPF или Policy Policy Framework - новая технология, которая позволяет легко обнаруживать спам. Gmail почитает SPF, если вы не отметите вручную эти письма, а не спам. Независимо от этого, если вы получили электронные письма на другом адресе, они, должно быть, тоже достигли Gmail. Проверьте свой спам полностью, так как Gmail не отбрасывает электронные письма даже при очень высоком подозрении на спам, а попадает в папку "Спам".

Вы можете настроить SPF, который позволяет вашему веб-серверу отправлять электронные письма, что приведет к тому, что Gmail будет принимать электронные письма, отправленные вашим веб-сервером, как аутентичные. См. http://www.mydigitallife.info/how-to-set-up-and-create-sender-policy-framework-spf-domain-dns-txt-record-with-wizard/ и мастер из Microsoft.

Ответ 5

вы можете изменить этот script, для отладки вашей проблемы,

$this->email->send();

к

if($this->email->send())
{
    echo 'Your email was sent.';
}

else
{
    show_error($this->email->print_debugger());
}

Ответ 6

Используйте следующий код

И не замораживайте, чтобы не удалось выполнить два параметра безопасности в Google.

1) https://www.google.com/settings/security/lesssecureapps < < включите его

2) https://accounts.google.com/b/0/DisplayUnlockCaptcha < < Нажмите "Продолжить"

** Отключите 2-ступенчатую аутентификацию, если она включена.

$config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_port' => 465,
        'smtp_user' => '[email protected]',    //email id
        'smtp_pass' => 'xxxxxxxxxxx',            // password
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");

    $this->email->from('[email protected]','my name');
    $this->email->to("[email protected]"); // email array
    $this->email->subject('email subject');   
    $this->email->message("my mail body");

    $result = $this->email->send();


    show_error($this->email->print_debugger());  // for debugging purpose :: remove this once it works...

Ответ 7

Я только что изменил код из RobinCominotto, чтобы он работал в office365.

PS: Я работал, когда размещал его в контроллере и вызывал эту функцию именно так. Когда я помещаю эти конфиги в файл email.php(файл конфигурации), больше не работает: (

    $ci = get_instance();
    $ci->load->library('email');
    $config['protocol'] = "smtp";
    $config['smtp_host'] = "smtp.office365.com";
    $config['smtp_port'] = "587";
    $config['smtp_user'] = "<HERE COMES YOUR EMAIL>"; 
    $config['smtp_pass'] = "<HERE COMES THE PASSWORD OF EMAIL>";
    $config['charset'] = "utf-8";
    $config['mailtype'] = "html";
    $config['newline'] = "\r\n";

    $ci->email->initialize($config);

    $ci->email->from('<HERE COMES YOUR EMAIL>', 'Blabla');
    $list = array('<HERE COMES TO EMAIL>', '<HERE COMES TO EMAIL>');
    $ci->email->to($list);
    $this->email->reply_to('<HERE COMES YOUR EMAIL>', 'Explendid Videos');
    $ci->email->subject('This is an email test');
    $ci->email->message('It is working. Great!');
    $ci->email->send();
    print_r($ci->email->print_debugger());