Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
function attachemant2()
	{

		$data = array(
		array("First Name" => "Nitya", "Last Name" => "Maity", "Email" => "nityamaity87@gmail.com", "Message" => "Test message by Nitya"),
		array("First Name" => "Codex", "Last Name" => "World", "Email" => "info@codexworld.com", "Message" => "Test message by CodexWorld"),
		array("First Name" => "John", "Last Name" => "Thomas", "Email" => "john@gmail.com", "Message" => "Test message by John"),
		array("First Name" => "Michael", "Last Name" => "Vicktor", "Email" => "michael@gmail.com", "Message" => "Test message by Michael"),
		array("First Name" => "Sarah", "Last Name" => "David", "Email" => "sarah@gmail.com", "Message" => "Test message by Sarah")
		);
		// file name for download
		$fileName = "codexworld_export_data" . date('Ymd') . ".xls";

		// headers for download
		header("Content-Disposition: attachment; filename=\"$fileName\"");
		header("Content-Type: application/vnd.ms-excel");

		$flag = false;
		foreach($data as $row) {
			if(!$flag) {
				// display column names as first row
				echo implode("\t", array_keys($row)) . "\n";
				$flag = true;
				echo "Swami";

			}
			// filter data
			array_walk($row, 'filterData');
			echo implode("\t", array_values($row)) . "\n";

		}
		$config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => 'vetri776@gmail.com', // change it to yours
  'smtp_pass' => '9578010375', // change it to yours
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
		);

		$this->load->library('email', $config);
		$this->load->library('email', NULL, 'ci_email');
		$this->email->set_newline("\r\n");
		$this->email->from('vetri776@gmail.com'); // change it to yours
		$this->email->to('vetrinature@gmail.com');// change it to yours
		$this->email->subject('Client Details');
		$this->email->message("Hi");
		$this->email->AddAttachment($fileName );
		if($this->email->send())
		{
			echo implode(" ",$data);
		}
		else
		{
			show_error($this->email->print_debugger());
		}
	}


What I have tried:

I have tried to create excel file and attach and send.but i faced this issue,
how to solve this issue...
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900