我尝试使用codeigniter电子邮件类发送电子邮件时出错。
我有一个错误: 无法连接到" localhost"的邮件服务器端口25,验证您的" SMTP"和" smtp_port"在php.ini中设置或使用ini_set()
如何测试在codeigniter中发送电子邮件?我也在使用localhost。这个问题只在我使用localhost时发生吗?
这是我的代码:
public function emailme() {
$this->load->library('email');
$message = $this->input->post('email_msg');
$this->email->from('iamjohnx3303@yahoo.com', 'John');
$this->email->to('iamjohnx3302@gmail.com');
$this->email->subject('Email Test');
$this->email->message($message);
$this->email->send();
}
答案 0 :(得分:3)
sendmail.ini
中的配置路径c:\xampp\sendmail\sendmail.ini
配置
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com
php.ini 中的
路径c:\xampp\xampp\php\php.ini
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
然后
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx@gmail.com',// your mail name
'smtp_pass' => '*****',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
$this->email->to('target@gmail.com'); //receiver mail
$this->email->subject('testing');
$this->email->message($message);
$this->email->send(); //sending mail
答案 1 :(得分:1)
在发送邮件脚本之前使用此
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'ValidEmailAccount@YourDomain.com');