The result from email sending is true but email is not received. My configs looks like this:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 587,
'smtp_user' => 'tomaivanovtomov#gmail.com',
'smtp_password' => 'abc9110033969qwe',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'smtp_timeout' => 10,
'smtp_crypto' => 'tls'
);
$this->load->library('email', $config);
If I try the other way with $this->email->initialize($config) and $this->load->library('email') before it, when try to send it I get an error:
fsockopen(): unable to connect to smtp.gmail.com:587 (Connection refused)
Try to modify the connection to use ssl instead of tls, and port 465 instead of 587 :
'smtp_port' => 465,
'smtp_crypto' => 'ssl'
Change smtp host with
'smtp_host' => 'ssl://smtp.gmail.com',
Check you smtp_port and provide correct your port number with
'smtp_port' => 587,
And change crypto type with ssl
'smtp_crypto' => 'ssl'
try to do it in following order.
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'abcdef#gmail.com'; //your email address
$config['smtp_pass'] = 'testingmails'; // password
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
$this->email->initialize($config);
Related
I want to send an email from my Gmail account through the website. how do I do that? I've tried every possible way but couldn't get the desired output.
public function mailuser(){
$config = Array(protocol' => 'ssmtp','smtp_host' => 'ssl://ssmtp.gmail.com','smtp_port' => 465,'smtp_user' => 'xxxx#gmail.com','smtp_pass' => 'xxxx','mailtype' => 'html');
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxx#gmail.com', 'Manoj');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('Email Subject');
$this->email->message('Email Message');
if($this->email->send()){
echo 'Success email Sent';
echo $this->email->print_debugger();
}
else{
echo 'Email Failed To Send';
echo $this->email->print_debugger();
}
}
I think you are using wrong parameters in config like ssmtp
protocol' => 'ssmtp','smtp_host' => 'ssl://ssmtp.gmail.com'
Your config array should look like :
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx#gmail.com',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$this->email->from('xxxx#gmail.com', 'Manoj');
$this->email->to('xxxxx#gmail.com');
$this->email->subject('Email Subject');
$this->email->message('Email Message');
$result = $this->email->send();
Also verify to enable extension extension=php_openssl.dll in php.ini.
if not please remove ;
this is my code to send email with gmail but it is not work , I am try hard to make it work for 4 days but still not work.
please help me, it was work before 6 day , after that not work , the server told me to change PHPMailer to SMTP Gmail , I am changed but still not work ...
i am register in Amazon SES Email , but i do not know how to use it, so i have 2 option : make this run in my normal server or change to Amazon SES , if SES is better chance learn me how to use it .
my site to test
my Controller
public function Send_Single_Email_Try ()
{
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'xx#gmail.com',
'smtp_pass' => 'xx',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', $email_config);
$this->email->from('someuser#gmail.com', 'invoice');
$this->email->to('test#test.com');
$this->email->subject('Invoice');
$this->email->message('Test');
$this->email->send();
if($send)
{
echo 1;
}
else
{
echo 0;
}
}
my JS
$(document).on('click','#SendEmailTry',function(e){
e.preventDefault();
$.ajax({
url:"<?php echo
base_url('Email/Send_Single_Email_Try/')?>",
type: "POST",
dataType: "text",
success:function(data)
{
if (data == 1)
{
alert("send");
}
else
{
alert("notsend");
}
},
error: function (jqXHR, textStatus, errorThrown)
{
alert("error")
}
});
});
Try this....
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'sender_mailid#gmail.com';
$config['smtp_pass'] = 'password';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('sender_mailid#gmail.com', 'sender_name');
$this->email->to('recipient#gmail.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
check and set your csrf protection from your site config file(yourproject/config/config.php) such as,
$config['csrf_protection'] = FALSE;
your rewrite code:
public function Send_Single_Email_Try ()
{
$this->output->enable_profiler(FALSE);
$email_config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'xx#gmail.com',
'smtp_pass' => 'xx',
'mailtype' => 'html',
'starttls' => true,
'newline' => "\r\n"
);
$this->load->library('email', $email_config);
$this->email->from('someuser#gmail.com', 'invoice');
$this->email->to('test#test.com');
$this->email->subject('Invoice');
$this->email->message('Test');
$send = $this->email->send();
if($send)
{
echo 1;
}
else
{
echo 0;
}
}
Email is not sent by codeigniter.please check and identify the erros.
MY controller code is:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'bilalshabbir3210#gmail.com', // change it to yours
'smtp_pass' => 'my pasword', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = '<h4>Email comessss</h4>';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('bilalshabbir3210#gmail.com'); // change it to yours
$this->email->to('bilalshabbir0909#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());
}
And error comes:
[]
enter image description here
The error makes it appear that your code cannot contact the SMTP server you've told it to use. A quick google implies that the server should be smtp.gmail.com.
Please use the following settings, this work very well with google
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 465,
'smtp_crypto' => 'ssl',
'smtp_timeout' => '30',
'smtp_user' => 'your_mail#gmail.com', // change it to yours
'smtp_pass' => 'your_gmail_password', // change it to yours
'charset' => 'iso-8859-1',
'crlf' => "\r\n",
'newline' => "\r\n",
'mailtype' => 'html',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->from('your_mail#gmail.com'); // change it to yours
$list = array('destination_list#gmail.com'); // change it to yours
$this->email->to($list);
$this->email->subject('This is an email test');
$message = '<h4>Email comessss</h4>';
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
} else {
show_error($this->email->print_debugger());
}
This code gives me an error when it is in live server. Its running in localhost but not running in live server. It gives error fsockopen():unable to connect
public function forgetPassword()
{
if(isset($_POST['email']) && !empty($_POST['email']))
{
$result = $this->Db_Function->loadDataForUpdate('wc_usr','wc_email',$_POST['email'],'nor');
if($result)
{
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'nileshivarni#gmail.com',
'smtp_pass' => 'Nilesh#1234',
'smtp_port' => 465,
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n"
);
$this->email->initialize($config);
$this->email->from('nileshivarni#gmail.com','Varni IT Solution');
$this->email->to($_POST['email']);
$this->email->subject('Password Recovery');
$msg = '<html><head></head><body>';
$msg .= '<p>Dear ' . $result[0]['wc_fullname']. ',</p>';
$msg .= '<p> <strong >Here is your Email and Password</strong></p>';
$msg .='<p>Email : <strong>'.$result[0]['wc_email'].'</strong></p>';
$msg .='<p>Password : <strong>'.base64_decode($result[0]['wc_password']).'</strong></p>';
$msg .='<p>Thank you</p>';
$msg .='<p>The team at Varni IT Solution</p>';
$msg .='</body></html>' ;
$this->email->message($msg);
if($this->email->send()){
$response['error'] = '1';
$response['success'] = "Your Password is successfully send to your email address !";
echo json_encode($response);
}
}
else
{
$response['error']='2';
$response['errorMsg']='Sorry ! Your Email is not registered with us!';
echo json_encode($response);
}
}
first of all if you are in any live server then it's not necessary to define :
$config = array( 'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'nileshivarni#gmail.com',
'smtp_pass' => 'Nilesh#1234',
'smtp_port' => 465);
above values for sending a mail : just define
$config = array(
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n");
That's completed. It's work in live server.
I am using codeigniter to send email.
function forget_pw() {
$this->load->library('email');
$config['smtp_host'] = 'host address';
$config['smtp_user'] = 'username';
$config['smtp_pass'] = 'password';
$this->email->initialize($config);
$this->email->from('admin#email.com', 'Admin');
$this->email->to('test#yahoo.com.hk');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
}
No any error show in console. But the email didn't send out.
You can create a function like this:
public function sendEmail($subject,$message)
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'xxxxx.xxxxxx.xxxxx',
'smtp_port' => 465,
'smtp_user' => 'xxxxx.xxxxxx.xxxxx',
'smtp_pass' => 'xxxxx.xxxxxx.xxxxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxxx.xxxxxx.xxxxx');
$this->email->to('xxxxx.xxxxxx.xxxxx');
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send())
{
echo 'Email send.';
}
else
{
show_error($this->email->print_debugger());
}
}
And use it like this $this->sendEmail('Title', 'Message'); Good luck