0

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.

7
  • 1
    Please edit your question and add more details: What happens when you send an email? Do you get an error? Which? Can you check the email server's queue? Is it still trying to send? (It may take a few days for an email to bounce while the server keeps retrying.) Might also help to improve the title, from "doesn't work" to a more specific problem. Commented Sep 4 at 14:11
  • Does it work if you replace $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, replacing return false; with echo $this->email->print_debugger(); should give you a more specific error. Commented Sep 4 at 14:33
  • Spelling error might be passing null here... $res['reciever'] Commented Sep 4 at 19:37
  • sslsmtp.gmail.com does not exist, you probably want smtp.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. Commented Sep 4 at 19:39
  • Note also that you can pass false as a parameter to $this->email->send() and it will capture debugging information, which you can then dump with $this->email->printDebugger(['headers']); Commented Sep 4 at 19:44

1 Answer 1

-1

Sending emails from a website is always a giant pain. The current internet email environment has taken drastic measures to prevent spam, and as a result it's pretty hard to just send an email and expect it to get delivered.

A lot of times the emails are getting flagged as spam. Have the site owner check his spam box. If it has your emails then get him to un-spam them and go back to your setup when he was getting the emails. If they are totally blocked, you can also try one of the online services that check the spamminess of your emails. They will recommend you add dkim records and do other stuff, but a lot of times that's a moving target and still not a guarantee that your emails will go where they need to go.

Using Google or Office 365 can help, but they have rate limits on how many emails you can send per hour and if your site gets a lot of traffic this can become a bottleneck. I have had some success using SendGrid, but you have to pay for an account (https://github.com/sendgrid/smtpapi-php).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.