send email by using codeigniter library via server - codeigniter

i want to send email using SMTP protocol Via server.my server is host gator.
enter image description here

You need configure user and pass in configs
specify your problem better

thanks... i done it with same code...
just change the port then its working....
here is code
function do_email($msg=NULL, $sub=NULL, $to=NULL, $from=NULL){
$this->load->library('email');
$config = array();
$config['protocol']='smtp';
$config['smtp_host']='localhost';
$config['smtp_port']='587';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from($from, $system_name);
$this->email->to($to);
$this->email->subject($sub);
$this->email->message($msg);
$email = $this->email->send();
}

Related

Using Google ReCaptcha

I am keen on using Google ReCaptcha. I have got the captcha on the page using the public key but don't know how to use the private key in my form processor document:
<?php
//SMTP SETTINGS
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.webhost.co.nz'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ‘xxxxx#xxxxxxxx.co.nz'; // SMTP username
$mail->Password = ‘xxxxx##xxxxxx’; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
$mail->Port = 465;
$mail->isHTML(true); // Set email format to HTML
//SMTP SETTINGS
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
print_r($_POST);
$mailheader = "From: $email";
$to = "tony#finelinecreative.co.nz"; // Here is email send to
$subject = "Finelinecreative Enquiry";
$message = "Name: $name<br/>Email: $email<br/>Message: $message";
// Send the mail
$mail->From=$mail->Username;
$mail->FromName = 'finelinecreative';
$mail->addAddress($to);
$mail->addReplyTo($email, $email);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->IsHTML(true);
$result = $mail->send();
header('location: http://www.finelinecreative.co.nz/index.php/thanks');
?>
Ideas please?
There's a great tutorial at https://codeforgeek.com/2014/12/google-recaptcha-tutorial/ that explains it pretty well.
In essence, you're checking if the $_POST variable 'g-recaptcha-response' exists (which, by including recaptcha on your form, is sent along with the other values on the form). If it is, you send a file_get_contents call (sending the secret key, the g-recaptcha-response POST value, and the user's IP address). You decode the result of that (which is sent as JSON, and you probably want to access it as key-value pairs), and find out whether the query was successful.
This is the relevant portion of their implementation.
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "Put your secret key here";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are spammer ! Get the #$%K out</h2>';
} else {
// Send the email. In your case, you can wrap pretty all of your preprocessor in this.
}

Codeigniter email issue, I'm struggling to send email one after another

I am tring to send mails through codeigniter email class. Following is a method from my controller :
$config['protocol'] = 'mail';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('xxx#yyy.zzz');
for($i=0; $i< count($data); $i++)
{
$this->email->to($data[$i]['email']);
$this->email->subject('Notification');
$this->email->message('EMAIL');
$this->email->send();
}
$admin_data = $this->admin_model->get_admin_detail();
$this->email->to($admin_data[0]['email']);
$this->email->subject('Notification');
$this->email->message('EMAIL');
$this->email->send();
I am getting mails using my script in for loop. But then it shows HTTP 500 Internal Server Error. And I did not get mail to my admin email.
Expected : emails to users using for loop [it's working]
and one email [after for loop ends] to admin mail.
Thanks.!
Try this...
$this->load->library('email');
$config['protocol'] = 'mail';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
for($i=0; $i< count($data); $i++)
{
$this->email->clear();
$this->email->from('xxx#yyy.zzz');
$this->email->to($data[$i]['email']);
$this->email->subject('Notification');
$this->email->message('EMAIL');
$this->email->send();
}
$admin_data = $this->admin_model->get_admin_detail();
$this->email->clear();
$this->email->from('xxx#yyy.zzz');
$this->email->to($admin_data[0]['email']);
$this->email->subject('Notification');
$this->email->message('EMAIL');
$this->email->send();

Codeigniter: Override variable in auto-loaded config file

I have the following:
config/email.php
$config['protocol'] = 'smtp';
$config['smtp_host'] = "xxxxxx";
$config['smtp_user'] = "xxxxxx";
$config['smtp_pass'] = "xxxxxx";
$config['smtp_port'] = xx;
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
So in most cases, I'm sending HTML with plain-text alternative emails. This config works perfectly.
Now in one special case, I'm wanting to send a plain-text email so I need to override that setting to:$config['mailtype'] = 'text';
How can I do that? I tried specifying a new config array and loading the library again but it still sends as HTML:
$email_config = Array(
'mailtype' => 'text'
);
$this->load->library('email', $email_config);
I think you need to call initialize when you don't load from a config file.
$this->email->initialize($email_config);
You should use:
$config['mailtype'] = 'text';
$this->email->initialize($config);

Can't send email via codeinginter using cpanel email account

I have problem when sending email from my server to somebody account
i mean that i need to send email from
myemail#mydomain.com to any another account Whether Live, hotmail or gmail etc.
of course that from PHP script
I have been created email account from my CPanel, and i tried to send email by this code.
$config['protocol'] = 'smtp';
$config['smtp_host'] = "mail.mydomain.com";
$config['smtp_user'] = "myemail#mydomain.com";
$config['smtp_pass'] = "password";
$config['smtp_port'] = "25";
$this->load->library('email',$config);
$this->email->from("myemail#mydomain.com", 'test');
$this->email->to("actualemail#live.com"); // the user email
$this->email->subject("hello");
$this->email->message("test test test");
if (!$this->email->send()) {
echo "error";
//$this->email->print_debugger();
exit;
}
//$this->email->print_debugger();
//exit;
echo "success";
Note that i'm using codeigniter framework.
The strange is there is no any problem in sending email , i get success message, but when i go to my receive email account i not found
any email. what to do, I'm boring form a lot of attempts :( .
try this:
$to = 'you#gmail.com';
$subject = 'my subject';
$msg = 'Hi..........';
$headers = "From: info#domain.com\r\nReply-To: info#domain.com";
$mail_sent = #mail( $to, $subject, $msg, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
It directly takes details from your server & sends mail.
This works fine on my site.

Call to a member function from() on a non-object in my mail settings

I wrote this code to sent a mail in codeigniter
$this->mailconfig['mailtype']='text';
$this->load->library('email', $this->mailconfig);
$this->email->from('ajithm#qburst.com','Tony');
$this->email->to($this->mail);
$this->email->subject('PASSWORD');
$this->email->message('Your password is:' . $password);
$this->email->send();
But i got a error as PHP Fatal error: Call to a member function from() on a non-object
Not sure if you can pass the config when loading the email library. In the docs this is a bit different:
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('ajithm#qburst.com','Tony');
$this->email->to($this->mail);
$this->email->subject('PASSWORD');
$this->email->message('Your password is:' . $password);
$this->email->send();

Resources