1

It's been 2 days struggling for email to get it to work.

I am using vestacp which is perfect in all cases but failed in sending email via PHP scripts. I have used traditional mail() function, SMTP and swift mailer too but nothing seems working.

I have setup a domain with Let's encrypt SSL in VestaCP and used A record in DNS for domain panel. And created info@domain.com in mail section which is working fine in RoundCube by vestacp i.e., x.x.x.x/webmail

I don't get any error while using mail() function and SMTP (Email is not sending obviously).

Codeigniter Mail Function - (No errors, no email)

$this->load->library('email');

$this->email->from('info@domain.com', 'Web Application');
$this->email->to($email);
$this->email->subject('domain.com - Change Password Link');

$message = base_url().'auth/redirect';
$message .= ''.' '.'Click on link to reset password. Thank you';


$this->email->message($message);            
$this->email->set_mailtype("html");
$this->email->send();

I get Unable to connect with TLS encryption when using Swift mailer.

Swiftmailer - (Error - Unable to connect with TLS encryption, no email)

try {
    $mail_host = 'ec2-x-x-xxx-xxx.ap-south-1.compute.amazonaws.com'; // Yup its aws
    $mail_port = '587'; // tried 25, 465
    $mail_user = 'info@domain.com';
    $mail_pass = 'xxx';
    // Create the Transport
    $transport = (new Swift_SmtpTransport($mail_host, $mail_port, 'tls'))
        ->setUsername($mail_user)
        ->setPassword($mail_pass);

    // Create the Mailer using your created Transport
    $mailer = new Swift_Mailer($transport);

    // Create a message
    $message = (new Swift_Message("Web App"))
        ->setFrom(array($mail_user => "Web app"))
        ->setTo([$to => ''])
        ->setSubject($subject)
        ->setBody($this->load->view("email/email_template", $data, TRUE), 'text/html');

    //Send the message
    $result = $mailer->send($message);
    if ($result) {
        return true;
    }
} catch (\Swift_TransportException $Ste) {
    $this->session->set_flashdata('error', $Ste->getMessage());
    return false;
} catch (\Swift_RfcComplianceException $Ste) {
    $this->session->set_flashdata('error', $Ste->getMessage());
    return false;
}
Muhammad Dyas Yaskur
  • 4,300
  • 8
  • 27
  • 48
Khan Sharukh
  • 761
  • 9
  • 19

0 Answers0