我正在按照教程使用gmail发送电子邮件,但我得到的是一个只挂起甚至不加载错误的页面。我正在使用MAMP,这可能是它无法正常工作的原因。
class Email extends CI_Controller{
public function __construct()
{
parent::__construct();
}
function index(){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email',
'smtp_pass' => 'pass'
);
$this->load->library('email',$config);
$this->email->set_newline("/r/n");
$this->email->from('email', 'George');
$this->email->to('email');
$this->email->subject('hey this is an email');
$this->email->message('this is the content of the email');
if($this->email->send()){
echo 'Your message was sent';
}else{
show_error($this->email->print_debugger());
}
}
}
答案 0 :(得分:7)
取消注释extension = php_openssl.dll
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someuser@gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', config);
$this->email->from('email@gmail.com', 'George');
$this->email->to('email@gmail.com');
$this->email->subject('hey this is an email');
$this->email->message('this is the content of the email');
$this->email->send();
echo $this->email->print_debugger();
希望这会起作用
答案 1 :(得分:0)
导致问题的一行是:
$this->email->set_newline("/r/n");
删除它并尝试发送电子邮件。
答案 2 :(得分:0)
我自己成功完成了这项工作,但通过发送config / email.php中的所有值。那部分无所谓。
基本上你是想通过@gmail帐户或自己的域名发送?如果您尝试浏览自己的域名,则需要将DNS更改为相关的Google设置:
答案 3 :(得分:0)
MAMP不附带openssl扩展名,但您可以自行创建。有关详细信息,请参阅this教程
答案 4 :(得分:-1)
首先使用标准smtp端口发布,并确保使用以下配置工作:
function index(){
$ config = Array( 'protocol'=> 'SMTP', 'smtp_host'=> 'smtp.googlemail.com', 'smtp_port'=> 25, 'smtp_user'=> '电子邮件', 'smtp_pass'=> '通过' );
$ this-> load-> library('email',$ config);
$ this-> email-> from('email','George'); $这个 - >的电子邮件 - >至( '电子邮件'); $ this-> email-> subject('嘿,这是一封电子邮件'); $ this-> email-> message('这是电子邮件的内容');
$ this-> email-> send(); }
一旦你尝试了这一切,并且所有工作都要仔细阅读: