I am trying to send form data to an email. The functions are running perfectly but email is not going to the specified email address. I am getting the response as 100 but there is no email received.
My controller:
<?php
class Contact extends CI_Controller {
public function sendemail()
{
$this->load->model('Contactmodel');
$response=array();
$response=$this->Contactmodel->sendemail();
echo json_encode($response);
}
}
?>
My model
<?php
class Contactmodel extends CI_Model
{
public function _construct()
{
parent::_construct();
}
public function sendemail()
{
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$returnarray = array();
$to_email = 'cse.akhilraj@gmail.com';
$this->email->to($to_email);
$this->email->from($email, $name);
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
$returnarray[0] = 100;
}
else
{
$returnarray[0] = 101;
}
return $returnarray;
}
}
?>
<?php
class Contactmodel extends CI_Model
{
public function _construct()
{
parent::_construct();
}
public function sendemail()
{
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$email_to= 'cse.akhilraj@gmail.com';
$email_subject= 'Enquiry';
$email_message = "Form details below.\n\n";
function clean_string($string)
{
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Comments: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
$this->email->to($email_to);
$this->email->from($headers);
$this->email->subject($email_subject);
$this->email->message($email_message);
$returnarray = array();
if($this->email->send())
{
$returnarray[0] = 100;
}
else
{
$returnarray[0] = 101;
}
return $returnarray;
}
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.