CodeIgniterでSMTPを設定しようとしています。すべてうまくいっており、ページに成功のメッセージが表示され、エラーなしで電子メールが送信されます。しかし、電子メールは配信されません。
以下は、私が使用しているコードです。
$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();
メールが届かない原因は何ですか?
以下のように変更してください。
$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();
php.ini ファイルを確認しましたか?試してみてください。もしそうでなければ、SPFを試してみてはいかがでしょうか。 SPF(Sender 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/ とウィザードを参照してください。