Send SMTP Mail Using PHP :: CI

0
1293


<?php

public function send_mail()
{
	$_POST = json_decode((file_get_contents('php://input')),true);


	$config = Array(
		'protocol' => 'smtp',
		'smtp_host' => 'ssl://smtp.googlemail.com',
		'smtp_port' => 465,
		'smtp_user' => '**********',
		'smtp_pass' => '*********', 
// Remember to allow third party secure authorisation for this
		'mailtype'  => 'html',
		'charset'   => 'iso-8859-1',
		'wordwrap' => TRUE
	);
	$this->load->library('email', $config);
	$this->email->set_newline("\r\n");


	$this->email->from($_POST['data']['from'], 'NAME TO SHOWN');
	$this->email->to($_POST['data']['to']);
	$this->email->cc($_POST['data']['cc']);
	$this->email->subject($_POST['data']['subject']);
	$this->email->message($_POST['data']['message']);  

	if(isset($_POST['attachment']) && sizeof($_POST['attachment']) > 0)
	{
		for ($i=0; $i < sizeof($_POST['attachment']); $i++) {
			$emailFile = "SERVER LINK HERE";

			$this->email->attach($emailFile);

		}
	}


	if($this->email->send())
	{
		$msg = "success";

	}
	else
	{
// echo $this->email->print_debugger();
		$msg = "error";
	}

	$result = array('msg' => $msg);
	echo json_encode($result);


}

?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here