Welcome Guest, Not a member yet? Register   Sign In
localhost setup for using MailServer
#1

I am developing locally on localhost. I am working on forgotpassword and have created the email to send to a user. I am getting an error "Failed to connect to mailserver at...".  For right now I am on local host but this thing needs to run on a public server. How do I develop so I can just change from my local environment to a public server. How do i get a mailserver to use while testing locally? I personally use gmail.
proof that an old dog can learn new tricks
Reply
#2

(This post was last modified: 06-27-2018, 03:18 AM by InsiteFX.)

When testing something like this I use my internet providers SMTP Server (Comcast).

All you need to do is edit the php.ini file and setup the link and SMTP Port number.

Then just sent the email to yourself at home.

Example:

Code:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.comcast.net
; http://php.net/smtp-port
smtp_port = 587

Hope that helps.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(06-27-2018, 03:13 AM)InsiteFX Wrote: When testing something like this I use my internet providers SMTP Server (Comcast).

All you need to do is edit the php.ini file and setup the link and SMTP Port number.

Then just sent the email to yourself at home.

Example:

Code:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.comcast.net
; http://php.net/smtp-port
smtp_port = 587

Hope that helps.
Thanks. I took care of the mods in php.ini. Now the code gets to a section below and gets stuck in the mail command.

PHP Code:
$headers "MIME-Version: 1.0" "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" "\r\n";
//additional headers
$headers .= 'From: R&D Substantiator<[email protected]>' "\r\n";
//send email
mail($to,$subject,$mailContent,$headers); 

What is mail()? I can't seem to step into it with my debugger.  Do I need to replace that with $this->email->send(); ?
proof that an old dog can learn new tricks
Reply
#4

MailTrap works quite well for testing, also.
Reply
#5

Thanks Kilishan. I took a look at it. Looks great but I think that is really overkill for what I am working on which is forgot password.
proof that an old dog can learn new tricks
Reply
#6

Just use that and use CodeIgniters Email Class.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

I am trying that! I wrote this little function:
public function send_mail($conditions = array()){
$this->load->library('email');
$email=$conditions[where]['email'];
$this->email->from('[email protected]', 'admin at Substantiator.com');
$this->email->to($email);
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
}

Where do I place this function? The code I got is not really sticking to the MVC paradigm. They have a file called userAccount.php which is in Models and has a include 'user.php'; directive at the top. user.php does extend CI_Model. But it is the userAccount.php code which is making the decision to send a password update email. This userAccount.php is not extending the CI_model. I tried putting my send_mail() function in user.php, but when I call it from userAccount.php like this:
send_mail($to,$subject,$mailContent,$headers);

I get an error: Message: Call to undefined function send_mail().

If I take it out of user.php and instead put it directly into userAccount.php, I get

Severity: Parsing Error

Message: syntax error, unexpected 'public' (T_PUBLIC)

So where do I put this CI email functionality?
proof that an old dog can learn new tricks
Reply
#8

You can add it to either the controller or model. I do not see you initializing the email config.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(This post was last modified: 06-28-2018, 06:43 AM by richb201.)

I was going to just use the defaults.  I will try pasting this, from the example, into a config/email.php

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

What do I do about the mailpath (and protocol)? This thing will be located on a public server at some point. Is sendmail a codeigniter file? I don't seem to have it on my PC at all.
proof that an old dog can learn new tricks
Reply
#10

On a live server it will probably be SMTP
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB