我很擅长使用CodeIgniter发送电子邮件。我搜索过任何教程和论坛来处理使用CodeIgniter发送电子邮件,但它们都不适合我。希望有人可以提供帮助。
这是我使用的控制器:
function send_email() {
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx@gmail.com',
'smtp_pass' => '****',
'mailtype' => 'text',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = '';
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx@gmail.com');
$this->email->to('xxxx@gmail.com');
$this->email->subjects('Email Testing');
$this->email->message($message);
if($this->email->send()) {
echo 'Email sent!';
} else {
show_error($this->email->print_debugger());
}
}
我已经编辑了php.ini作为论坛说,如:
;For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail
; ... or under UNIX:
;
; extension=msql.so
extension=php_openssl.dll
我使用的是Apache / 2.2.22(Ubuntu)服务器。
当我尝试调用该函数时,它显示空白页面。有编辑的配置吗?请给出你的建议。谢谢。
更新
这是我在php.ini中编辑的display_errors和error_reporting:
; display_errors
Default Value: On
Development Value: On
Production Value: On
; error_reporting
Default Value: E_ALL & ~E_NOTICE
Development Value: E_ALL | E_STRICT
Production Value: E_ALL & ~E_DEPRECATED
答案 0 :(得分:0)
轻松使用PHPMailer
$this->load->library('PHPMailer/PHPMailer');
$mail=new PHPMailer(); //creat PHPMailer object
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; //needs login information
$mail->SMTPSecure = "tls"; //specifies tls security
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; //gmail smtp port
$dd3=$this->db->query("select * from email where eid=1")->row_array();;
/******************* Set Your Credentials********************/
$mail->Username = 'xxxx'; //SMTP gmail address
$mail->Password = 'xxx'; // SMTP account password
$mail->From = 'xxx'; //sender's gmail address
$mail->FromName = "from";
$mail->AddAddress("to");//receiver's e-mail address
$mail->Subject = $subject;//e-mail subject
$mail->Body ="message";//e-mail message
$mail->WordWrap = 50;
if(!$mail->Send())
{
$status='Message was not sent.';
}
else
{
$status='Message has been sent.';
// echo $status;
}
答案 1 :(得分:0)
在codeigniter中试试!!
public function sendEmail($email,$subject,$message)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xyz@gmail.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xyz@gmail.com');
$this->email->to($email);
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
echo 'Email send.';
}
else
{
show_error($this->email->print_debugger());
}
}
public function send_email()
{
$email="abc@gmail.com";
$subject="Your subject";
$message="You can write html tags in this message";
$this->sendEmail($email,$subject,$message);
}