sending email from gmail using xampp - php

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

Related

Unable to send email in live server in codeingiter

Error screentshot Hello guyz i am doing sending mail function in codeingniter, Same email function working in localhost but it did not work in live server i cant understand this error please help me..
This is my Email code:
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email', // change it to yours
'smtp_pass' => 'password', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = "
<html>
<head>
<title>Verification Code</title>
</head>
<body>
<h2>Thank you for Registering.</h2>
<p>Your Account:</p>
<p>Dear: ".$firstname."</p>
<p>Please click the link below to activate your account.</p>
<h4><a href='".base_url()."welcome/activate/".$id."/".$code."'>Activate My Account</a></h4>
</body>
</html>
";
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($config['smtp_user']);
$this->email->to($email);
$this->email->subject('Signup Verification Email');
$this->email->message($message);
//sending email
if($this->email->send()){
$this->session->set_flashdata('message','Register Successfull And your Activation link send in Email Please Verify Your Account');
}
else{
$this->session->set_flashdata('message', $this->email->print_debugger());
}
ERROR:
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
The error you are showing is not related to your code rather its authentication error mean google servers are not allowing you to sign in.
Now in order to run this code, make sure you are using the right username and password.
After that, you have to turn on "Allow less secure apps" option from your Google/Gmail account.
After that, your code should be able to send an email.
Also, When you have uploaded your script into web host then you should use the email address of your domain name, like support#yourDomain.com it looks more professional.
Given below code is fully working code. Before you run it you must create an email address like admin#yourDomain.com from your hosting panel where there will be an option of email management.
$this->load->library('email');
$encodeEmail = bin2hex('email#gmail.com']);
$this->email->from('admin#yourDomain.com', 'Your Domain');
$this->email->to('email#gmail.com');
$this->email->subject('Email Verification Required');
$url = site_url() . 'verify/' . $data['verification'] . '/' . $encodeEmail;
$message = "";
$message .= "You have signed up with our website \r\n";
$message .= "Please click on given below link to verify and activitate your account. \r\n" . $url;
$this->email->message($message);
$this->email->send();

How to send email from localhost using CodeIgniter with Gmail

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 cannot send any emails using Codeigniter

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.

Adding subject line for sending an email in codeigniter php

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

sendmail fails on CodeIgniter but works on CLI

I have sendmail installed on a CentOS 6 server that seems to work well given that I can send a test message using CLI.
However, when trying to send a test message using CodeIgniter's email class, there seems to be some problem. My email.php config is
$config['protocol'] = 'sendmail';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
The controller for testing email:
$this->load->library('email');
$this->email->from('your#example.com', 'from name');
$this->email->to('someone#somewhere.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
When I send the test message through CodeIgniter, I get this error message
Exit status code: 71
Unable to open a socket to Sendmail. Please check settings.
Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.
When switching to SMTP or mail in the config I still get errors.
Any suggestions where to start trying to troubleshoot this problem?
Try Something like this
$this->load->library('email');
$config['protocol']='smtp';
$config['smtp_host']='your host';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='your mail id';
$config['smtp_pass']='your password';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['mailtype'] = 'html';
$this->email->initialize($config); //intializing config array
$this->email->from('your#example.com', 'Site name');
$this->email->to('someone#somewhere.com');
$this->email->subject('Mail');
$this->email->message('Your message');
$this->email->send();
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '******#gmail.com',
'smtp_pass' => '**********',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
//send email with #temp_pass as a link
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('**********#gmail.com', "Title");
$this->email->to($email);
$this->email->subject("Added");
$message = "<p>This email has been sent as a request to added</p>";
$this->email->message($message);
$this->email->send();
Try these.
Make sure apache is added to smmsp group.
id apache
If note add to group
usermod -g smmsp apache
chmod -v 2755 /usr/sbin/sendmail.sendmail
change config['mailpath'] to /use/sbin/sendmail.sendmail
If these tweeks didn't work,
chmod 777 /var/spool/clientmqueue
Its a security risk link

Categories