我正在尝试在CodeIgniter上设置SMTP。一切正常,我在页面上收到成功消息,发送的电子邮件没有错误。但是,电子邮件未送达。
以下是我使用的代码:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'my-email@gmail.com',
'smtp_pass' => '***',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->from('my-email@gmail.com', 'Explendid Videos');
$this->email->to('my-email@gmail.com');
$this->email->reply_to('my-email@gmail.com', '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();
可能的原因是,电子邮件实际上并未送达。
答案 0 :(得分:30)
将其更改为以下内容:
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "blablabla@gmail.com";
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('blablabla@gmail.com', 'Blabla');
$list = array('xxx@gmail.com');
$ci->email->to($list);
$this->email->reply_to('my-email@gmail.com', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();
答案 1 :(得分:4)
这是apache2服务器上的工作,ci 2.1.4:它非常简单: 首先在application / config目录下创建一个名为email.php的文件,然后在其中键入以下代码〜>
<?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";
?>
然后在你的application / controllers目录下创建一个名为email.php的文件,然后输入这段代码〜&gt;
<?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('some@of.mailaddress', 'ur Name');
$this->email->to('email@detiny.your');
$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();
}
}
}
?>
答案 2 :(得分:3)
替换
$config['protocol'] = 'smtp';
到
$config['protocol'] = 'sendmail';
答案 3 :(得分:0)
你检查过你的php.ini文件吗?试试吧。如果没有那么也许你也可以尝试SPF。 SPF或发件人策略框架是一种新技术,可以轻松检测垃圾邮件。 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的向导。
答案 4 :(得分:0)
您可以更改此脚本,以调试您的问题,
$this->email->send();
到
if($this->email->send())
{
echo 'Your email was sent.';
}
else
{
show_error($this->email->print_debugger());
}
答案 5 :(得分:0)
使用以下代码
并且不要忘记在谷歌中无法遵循两个安全设置。
1)https://www.google.com/settings/security/lesssecureapps&lt;&lt;打开它
2)https://accounts.google.com/b/0/DisplayUnlockCaptcha&lt;&lt;点击继续
**如果已启用,请关闭2步验证。
.one-col{
margin-left: 4%;
width: 4.66666666667%;
}
.eleven-cols{
margin-left: 4%;
width: 51.3333333334%;
}
.one-col:first-child,.eleven-cols:first-child{
margin-left: 0;
}
答案 6 :(得分:0)
我刚修改了 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());