Setting Up Emails in Code Igniter 2.02 - codeigniter

I’m getting a lot of errors. And I've tried several suggestion across different sites, deleted the parent function, removed the array, updated my php ini file, no luck.
This is the first of 13 errors I’m getting.
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?)
Filename: libraries/Email.php
Line Number: 1673
Someone please help.
class Email extends CI_Controller
{
function index()
{
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'myemail#gmail.com';
$config['smtp_pass'] = 'mypassword';
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('myemail#gmail.com', 'My Name');
$this->email->to('myemail#gmail.com');
$this->email->subject('This is an email test');
$this->email->message('Its working. Great!');
if($this->email->send())
{
echo 'Your email was sent, dude.';
}
else
{
show_error($this->email->print_debugger());
}
}
}

Use a phpinfo(); statement in a .php file to check if the openssl extension actually loaded.
In your php.ini enable php_openssl
extension=php_openssl.so
if you are on Windows, then
extension=php_openssl.dll

Mayowa:
Perhaps I'm a little late and you already has this solved.
After searching a lot in the web I found out that for mail configuration simple quotes and double quotes is not the same.
I use the /application/config/email.php file and after many attempts I found out that this will not work:
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'myemail#gmail.com';
$config['smtp_pass'] = 'mypassword';
But this will:
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.googlemail.com";
$config['smtp_port'] = 465;
$config['smtp_user'] = "myemail#gmail.com";
$config['smtp_pass'] = "mypassword";
Hope it helps.

Related

Fatal error: Uncaught Error: Call to undefined method PHPMailer\PHPMailer\PHPMailer::setForm()

here is my code
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
if(isset($_POST["send"])){
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'random#gmail.com'; // Your gmail
$mail->Password = 'rqbsmgrfefohmokx'; // Your gmail password
$mail->SMTPSecure= 'ssl';
$mail->Port = 465;
$mail->setForm('random#gmail.com'); // Your gmail
$mail->addAdress($_POST["email"]);
$mail->isHTML(true);
$mail->Subject = $_POST["subject"];
$mail->Body = $_POST["message"];
$mail->send();
echo
"
<script>
alert('Sent Succesfully');
document.location.href = 'index.php';
</script>
" ;
}
?>
i got this error
Fatal error: Uncaught Error: Call to undefined method PHPMailer\PHPMailer\PHPMailer::setForm() in C:\xampp\htdocs\sendmail\send.php:20 Stack trace: #0 {main} thrown in C:\xampp\htdocs\sendmail\send.php on line 20 Any ideas???
I really dont know from what this error comes... so i hope someone to help me/guide me
The most important thing to do in situations like this is read the error message. In this case the message is telling you that the setForm method does not exist. This is correct, and if you go and look at any of the PHPMailer examples or drill into the class itself, you’ll realise that the method name you’re looking for is setFrom, with the r and o the other way around.

How to send email in xampp localhost using PHPmailer?

I have attached two different PDF files (mnlocalXampp and rnlocalXampp) that is phpinfo of two different pcs. I have checked both information and seem that both have same information and using same version of PHP but I'm receiving email in mnlocalXampp but not in rnlocalXampp. I also activated openssl in both but i am still not receiving email in rnlocalxampp. Can anyone please look at both the files and let me know what difference in that files and how to configure.
<?php
require 'email_class/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
$mail->Host = 'cp-in-10.webhostbox.net'; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = '465'; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = 'mn#infotech.com'; //Sets SMTP username
$mail->Password = 'xxxxxxx'; //Sets SMTP password
$mail->SMTPSecure = 'ssl'; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = 'mn#infotech.com'; //Sets the From email address for the message
$mail->FromName = "mn"; //Sets the From name of the message
$mail->AddAddress("m#infotech.com"); //Adds a "To" address
$mail->AddCC("m#infotech.com"); //Adds a "Cc" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$mail->IsHTML(true); //Sets message type to HTML
$mail->Subject = 'Project CMS'; //Sets the Subject of the message
$mail->Body = $message; //An HTML or plain text message body
$mail->AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf');
$mail->Send(); ?>
The above sample code is email configuration of mnlocaXampp. For the rnlocalXampp I'm using different Port(Port number: 25), Hosting, SSL enabled.
mnlocalXampp
rnlocalXampp
Thanks in advance
Difficult to know where to start.
You've based your code on an obsolete example and you're using an old version of PHPMailer, so get the latest, and base your code on the examples provided.
You're not defining $doc before you use it.
addStringAttachment is the wrong method to use if you're trying to send a local file; use addAttachment instead.
The definition of $headers is pointless.
There's no point in CC'ing an address you're already sending to.
You have no error checking anywhere.
Resolving some of the above items may help to fix your problem.

Codeigniter login issue.

I have codeigniter powered application and whenever i tried to log in on local server it doesn't let me in without any error message. But when I login in live server it works fine.
#What might be main causes of this issue.
#My config file and database settings are correct
$config['sess_match_useragent'] = FALSE;
$config['phpass_hash_portable'] = TRUE;
//database settings:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'alumniconnect';
$db['default']['dbdriver'] = 'mysql';
I am using phpass for hashing password and tank_auth for authentication.
Thanks in advance.

config email yahoo, AOL for codeigniter from the local server

I used the following code for yahoo and it did not work, can you help where I am doing wrong. The same code when I used for the gmail with host as smtp.gmail.com it worked well. I am trying to send an email from the local server using yahoo, AOL, windows hotmail . The following is a file created in application/config folder with the name email.php
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.mail.yahoo.com";
$config['smtp_user'] = "myusername#yahoo.com";
$config['smtp_pass'] = "**************";
$config['smtp_port'] = "465";
$config['charset']="utf-8";
$config['newline']="\r";
$config['crlf'] = "\r";
The working code for gmail
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_user'] = "username#gmail.com";
$config['smtp_pass'] = "*****";
$config['smtp_port'] = '465';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['crlf'] = "\r\n";
Yahoo uses port 995 as the outgoing mail port
http://www.emailaddressmanager.com/tips/mail-settings.html

CodeIgniter Database Connection Issue

I'm using CodeIgniter, and I'm not able to use my database with it. I'm following this tutorial exactly, but when I open in localhost I receive a 404 page.
You need to set up your application/config/database.
Here you need to add your information for your database.
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "yourdbusername";
$db['default']['password'] = "password_for_db";
$db['default']['database'] = "name_of_db";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
Have you done it?
If you're getting a 404, it may not be your database connection. Check your routing, and be sure that you are accessing a page that does indeed exist. If you're accessing a controller that loads a view, stop loading the view for now and test the connection directly from the controller - output "YES" if it is, and "NO" if anything else.
If your problem persists, double-check your database-connection configuration. Lastly, I would suggest you follow the documentation rather than another website when you are getting familiar with a framework. You can view the documentation for the Database class at http://codeigniter.com/user_guide/database/index.html
Do you try http://localhost/CodeIgniter/index.php/employee/GetAll ?
Are you using CodeIgniter 2 ?

Resources