My website was developed in PHP using the CodeIgniter framework. On the development server, everything worked perfectly, but after migrating the site to Prohoster, the email sending feature stopped functioning.
At first, I assumed it was a misconfiguration in the SMTP settings, but the hosting support team confirmed that everything was set up correctly.
The site owner publishes information about his products, and when a visitor submits the contact form, the system should send an email notification to the owner, allowing him to respond directly to the customer.
During initial testing with Prohoster’s SMTP credentials, the email was sent successfully. However, since that time, every attempt to send a message through the contact form results in an error. I even tried switching to Gmail's SMTP settings, but the issue persists.
Here’s a snippet of the code I’m using. Has anyone faced a similar situation or knows how to fix it? I’m still new to PHP, so I might be missing something, but I’ve done my best to explain the issue.
public function send_mail($res)
{
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'sslsmtp.gmail.com'; // --- i tried with ssl://smtp.gmail.com, same thing happens
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = '123456';
$this->email->initialize($config);
$this->email->from($res['sender_email'], $res['sender_name']);
$this->email->to($res['reciever']);
$this->email->reply_to($res['sender_email'], $res['sender_name']);
$this->email->subject('Email from site.');
$this->email->message($res['message']);
if ($this->email->send()) {
return true;
} else {
return false;
}
//configure mail agent...
}
I tried to set up mail myself and figure out the problem, but I could not do it due to the lack of knowledge in this area.
$res['sender_email']in the->from(...)with[email protected]? Some servers may refuse to send your email if the smtp account differs from the from address. Also, replacingreturn false;withecho $this->email->print_debugger();should give you a more specific error.$res['reciever']sslsmtp.gmail.comdoes not exist, you probably wantsmtp.gmail.com. SSL is implied via use of port 465, but you might need to set$config['SMTPCrypto'] = 'ssl';if CodeIgniter doesn't do it for you.falseas a parameter to$this->email->send()and it will capture debugging information, which you can then dump with$this->email->printDebugger(['headers']);