Applying for a job need to send an email with some of the details like name,phonenumber,email,current ctc etcc..Email is sending correctly but the problem is while sending an email in subject line i need to include name email ctc...for this i have done this but it is not accepting in this format.
$name = $this->input->post('fullname');
$email = $this->input->post('email');
$phone = $this->input->post('mobilenumber');
$currentemploymentstatus = $this->input->post('current_employment_status');
//set to_email id to which you want to receive mails
$to_email = 'yyyy#gmail.com';
$config=Array(
'protocol'=> 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
'smtp_port' => '465', //smtp port number
'smtp_user' => 'xxxxxx#gmail.com',
'smtp_pass' => 'PASSWORD123', //$from_email password
'mailtype' =>'html',
'newline' =>"\r\n",
'crlf' =>"\r\n",
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = array();
$message[] = 'Fullname : '.trim($name).' ';
$message[] = 'Email : '.trim($email).' ';
$message[] = 'Mobile : '.trim($phone).' ';
$message[] = 'Current Employment Status : '.trim($currentemploymentstatus).' ';
//$message = implode(PHP_EOL, $message);
$message = implode('<br>', $message);
//send mail
$this->load->library('email',$config);
$this->email->from($email);
$this->email->to($to_email);
//$list = array();
$this->email->subject($name|$email);
$this->email->message($message);
$this->email->set_newline("\r\n");
$this->email->set_mailtype("html");
if ($this->email->send())
{
$this->flash->success('Thank you for applying to this post we will get back to you soon!</div>');
redirect('apply');
}
else
{
$this->flash->success('There is error in sending mail! Please try again later');
redirect('apply');
}
}
Just Solved by adding this code.
$subject = $name .' | '.$currentemploymentstatus .' | '.$expectedctc .' | '.$primaryskills;
$this->email->subject($subject);
For your problem try changing "|" to .'|'
To clean up your code and to make your life easier:
If you are using CI, check out my repository on setting up an email_model to simplify the code you are using. Instead of loading the config stuff for the library all you will need to do is hit the model to send to email queue and hit the model a second time to process the queue
https://github.com/ddell003/Email_model
Related
Hello everyone, I'm currently working on a CodeIgniter application in which user will be able to create their own accounts,etc.
I'm trying to create a function to recover password in case is lost or forgotten.
Here is my code:
public function admin_recover(){
$this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[7]|valid_email');
if($this->form_validation->run() == FALSE){
//Load View Into Template
$this->template->load('admin', 'login', 'users/recover');
} else {
//Get Post Data
$email = $this->input->post('email');
$password = $this->input->post('password');
$user_email = $this->User_model->get_list();
if($user_email){
$user_email_data = array(
'email' => true
);
///////// Sending email
// Configure email library
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$config['crlf'] = '\r\n';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['priority']=1;
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.gmail.com';
$config['smtp_port']='25';
$config['smtp_timeout']='30';
$config['smtp_user']='kuaf1998#gmail.com';
$config['smtp_pass']='mypassword';
$config['newline']="\r\n";
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('no-reply#socialgeek.com', 'Social Geek');
$this->email->to('kebin1421#hotmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
if($this->email->send())
$this->session->set_flashdata("success","Email sent successfully.");
else
$this->session->set_flashdata("error","Error in sending Email.");
echo $this->email->print_debugger();
//////////////
}
}
}
I'm using the gmail smtp service to send emails from my localhost but I'm still unable to make it happen. Any idea how can I fix this?
I already did some changes on(I'm using xampp) the ini file which is found on my xampp>php>php.ini
When I go to the view, I get this error:
Thanks for helping.
Try to use these configuration settings below and let me know if it works for you.
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'user#gmail.com',
'smtp_pass' => 'yourpassword',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
I have created a controller and made a test function in the controller to test if the email is sent or not.
I checked with different email addresses, but didn't succeed. This is my code example:
public function sendmail() {
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$user_id = 1;
$name = 'Mark Alan';
$this->email->set_newline("\r\n");
$this->email->from('info#domainname.com', "Test Name");
$this->email->to('test#domainname.com');
$this->email->subject('Test Mail');
$this->email->message('This is a test message');
$this->email->send();
echo $this->email->print_debugger();
}
With Codeigniter (assuming you have auto-loaded the email library) you can either set an email preference in a config file, named email.php and these preferences are loaded automatically from there. It could look like:
// Setting Email Preferences
$config['useragent'] = 'CodeIgniter'; // Mail engine switcher: 'CodeIgniter' or could be 'PHPMailer'
$config['protocol'] = 'smtp'; // 'mail', 'sendmail', or 'smtp'
$config['mailpath'] = '/usr/sbin/sendmail';
or like in your example, you can set them manually, but need to initialize it, so don't forget this line after defining your $config[] array:
$this->email->initialize($config);
Try this code:
function sendMail()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com', //Your Host
'smtp_port' => 465, // Add 25 port if you sending from your smtp mail server
'smtp_user' => 'xxx#gmail.com', // change it to yours, server email
'smtp_pass' => 'xxx', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = '';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#gmail.com'); // change it to yours
$this->email->to('xxx#gmail.com');// change it to yours
$this->email->subject('Resume from JobsBuddy for your Job posting');
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
Note: Please add your smtp port and your smtp email account detail.
I already watch and read all videos and the questions related to the problem "how to send email in php from gmail using XAMPP?? " . It run but the execution in SENDMAIL.ini is not working well
img Problem #1
this pic shown, when I clicked the enter button, the localhost/ex2/here.php or the name of your php file will permanently load unless you click the X button on the cmd of sendmail.exe..
When I clicked the X button on the cmd of sendmail.exe, this message will shown on my php file img Problem #2
And this is my code in sending email from gmail:
<?php
$message = "This message will directly POSTED to your GMAIL account";
$headers = "From: rence.samboy#gmail.com";
if(mail('rence.samboy#gmail.com', 'Example', $message, $headers))
{
echo "Text message is sent to rence.samboy#gmail.com.....<BR/>";
}
else
{
echo "Not Work..";
}
?>
**Much appreciate if you can help me to fix my problem** :)
Well... for sending email, you need to set your gmail configuration first, such as protocol, smtp port, etc.
For me... I'm using CodeIgnitor framework and this code that I've added in my controller:
public function send_mail() {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465, //or 587
'smtp_timeout' => 7,
'smtp_user' => 'xxx#gmail.com', //your gmail account
'smtp_pass' => 'xxx', //your gmail password
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE,
'newline' => "\r\n"
);
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$subject = $_POST["subject"];
$phone = $_POST["phone"];
$shipment_code = $_POST["shipment_code"];
$array = "Phone No: ".$phone."<br>Email: ".$email."<br>Shipment Code: ".$shipment_code."<br>Message: ".$message;
//Load email library
$this->load->library('email', $config);
$this->email->from('xxx#gmail.com');
$this->email->to('xxx#xxx.com');
$this->email->cc($email);
$this->email->subject($subject);
$this->email->message($array);
//Send mail
if($this->email->send())
$this->session->set_flashdata('email_sent',"<h2>Your email was sent successfully.</h2>");
else
$this->session->set_flashdata('email_sent',"Error in sending Email.");
echo $this->email->print_debugger();
$this->load->view('views_contactus');
}
If you want to see the view, then visit this.
php.ini
SMTP=smtp.gmail.com
smtp_port=465
sendmail_from = YOUR_MAIL#gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail.ini
smtp_server=smtp.gmail.com
smtp_port=465
error_logfile=error.log
debug_logfile=debug.log
auth_username=YOUR_MAIL#gmail.com
auth_password=YOUR_MAIL_PASS
force_sender=YOUR_MAIL#gmail.com
php.ini
extension=php_openssl.dll
I want to send an email verification link to the user with PHP CodeIgniter.
This is my controller function.
public function Sent_Confirmation_Email()
{
$emailid = $this->uri->segment(3);
$verificationLink = base_url() . 'MainController/Confirm_Activation/'.$emailid;
$msg .= "Please use the link below to activate your account..<br /><br /><br />";
$msg .= "<a href='".$verificationLink."' target='_blank'>VERIFY EMAIL</a><br /><br /><br />";
$msg .= "Kind regards,<br />";
$msg .= "Company Name";
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'sender#gmail.com',
'smtp_pass' => 'password'
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->isHTML(true);
$this->email->from("sender#gmail.com");
$this->email->to("$emailid");
$this->email->subject("Email Confirmation - Courses and Tutors");
$this->email->message($msg);
if($this->email->send())
{
$this->session->set_flashdata('msg', 'A confirmation email has been sent to ' . $emailid .'. Please activate your account using the link provided.');
redirect(base_url() . 'MainController/EConfirmationPage/'.$emailid);
} else {
show_error($this->email->print_debugger());
}
}
Note that I am sending emails from my localhost. I receive the email but the problem is it shows the html tags as well. This is the email which I received:
Please use the link below to activate your account..<br /><br /><br /><a
href='http://localhost/tutorhunt/MainController/Confirm_Activation/fareedshuja#gmail.com'
target='_blank'>VERIFY EMAIL</a><br /><br /><br />Kind regards,<br />Company
Name
Try to initialize email library and add mailtype as following
$this->email->initialize(array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://mailserver',
'smtp_user' => 'user',
'smtp_pass' => 'password',
'smtp_port' => 465,
'crlf' => "\r\n",
'newline' => "\r\n",
'mailtype' => 'html',
));
To Send Verification Link In Email Using Email Template is simpler than adding HTML content as a message and send it.
Creare an array of the variable which you want to send in an email.
Load that email template view and load that variable array and set the variable in the template properly.
Here is the code sample:
$this->email->set_newline("\r\n");
$this->email->isHTML(true);
$this->email->from("sender#gmail.com");
$this->email->to("$emailid");
$this->email->subject("Email Confirmation - Courses and Tutors");
$template_data = array(
'verificationLink' => base_url() . 'MainController/Confirm_Activation/'.$emailid,
'message' => 'Please use the link below to activate your account..',
'company_name' => 'test company'
);
$body = $this->load->view ('your_view.php', ['template_data'=>$template_data], TRUE); //Set the variable in template Properly
$this->email->message ( $body );
if($this->email->send())
{
$this->session->set_flashdata('msg', 'A confirmation email has been sent to ' . $emailid .'. Please activate your account using the link provided.');
redirect(base_url() . 'MainController/EConfirmationPage/'.$emailid);
} else {
show_error($this->email->print_debugger());
}
I have some problems, meaning that I don't receive mail from a form...
the code looks like this:
public function send_email(){
$this->load->library("form_validation");
$this->form_validation->set_rules("fullName", "Full Name", "required|alpha|xss_clean");
$this->form_validation->set_rules("email", "Email Address", "required|valid_email|xss_clean");
$this->form_validation->set_rules("message", "Message", "required|xss_clean");
if($this->form_validation->run() == FALSE){
$data["message"] = "";
$this->load->view("site_header");
$this->load->view("site_nav");
$this->load->view("content_comment", $data);
$this->load->view("site_footer");
}else{
$data["message"] = "The email was successfully been sent!";
$this->load->library("email");
$this->email->from(set_value("email"), set_value("fullName"));
$this->email->to("paulharbuz#gmail.com");
$this->email->subject("Message from our form");
$this->email->message(set_value("message"));
$this->email->send();
echo $this->email->print_debugger();
$this->load->view("site_header");
$this->load->view("site_nav");
$this->load->view("content_comment", $data);
$this->load->view("site_footer");
}
}
And i get an error that looks like this:
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.**
Is this from my php.ini file?
i've set my files reading this part on http://php.net/manual/en/ref.mail.php
i found the solution: create a file in config: email.php that looks like this
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| EMAIL CONFING
| -------------------------------------------------------------------
| Configuration of outgoing mail server.
| */
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$config['crlf'] = '\r\n';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['priority']=1;
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='gcc.sandbox#gmail.com';
$config['smtp_pass']='qwaszx12';
$config['newline']="\r\n";
/* End of file email.php */
/* Location: ./system/application/config/email.php */
then load this in your main controller like: $this->email->initialize($this->config->config); and that's it!
simply add this code to you helper file and call the function when you want to send mail the following method to send an email...
function send_mail($to,$subject,$message) {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx#xxxx',
'smtp_pass' => 'xxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from($config['smtp_user'],"Your name");
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
$result = $this->email->send();
return $result;
}
$string = 'mail content';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: z' . "\r\n";
mail(email, 'subject', $string, $headers);
I want to add little more knowledge into it if you are using gmail so this cannot be done by your own password it can be done by using specific Google password . if you get error like require application-specific password.
than search it in Google and get one and type in the field below as i did.
$config['smtp_pass']='application-specific password';