Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to sent mail using smtp?
  • Hello,

    I am trying sent mail on contact form submitting, but get error following:
    Fuel\Core\PhpErrorException [ Warning ]:
    stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)

    PKGPATH/email/classes/email/driver/smtp.php @ line 125

    I am using Gmail smtp to sent mail.
    Here my smtp configure:
    'smtp' => array(
    'host'     => 'ssl://smtp.gmail.com',
    'port'     => 465,
    'username' => 'user@gmail.com',
    'password' => 'userpassword',
    'timeout'  => 5,
    'starttls' => false,
    'options'  => array(
    ),
    ),
    And here my controller code:
    class Controller_contactus extends Controller {

        public function action_contact(){
            if (Input::is_ajax()) {
                $name = Input::post('name');
                $partner = Input::post('partner');
                $emailid = Input::post('emailid');
                $date = Input::post('date');
                $location = Input::post('location');
                $content1 = Input::post('content1');
                $content2 = Input::post('content2');
                           

                $email = \Email::forge();  
                $email = \Email::forge (array(
                   'driver' => 'smtp', 
                ));
                $email->priority(Email::P_HIGH);
                $email->from('admin@gmail.com', 'person1');
                $email->to('user@gmail.com', 'person2'); 
                $email->subject('Contact us'); 
                $email->body('contents of mail'); 
                
                if($email->send()){
                    echo 1;
                }else{
                    echo 'mail not sent';
                }
            }
        }
    }
  • Could be a million things.

    What platform does your webserver run on?

    Start by some debugging on that platform, run this from the commandline:

     <?php

     error_reporting(E_ALL);

     print "DNS\n";
     var_dump(getmxrr('gmail.com',$result));
     var_dump($result);
     $use_ip=gethostbyname($result[0]);
     print "IPV4 address = $use_ip\n";

     print "\nIf you've got this far without errors then problem is with your SSL config\n";
     $calocns=openssl_get_cert_locations();
     if (count($calocns)) {
         print "Check you've got your cacerts deployed in one of the following locations\n";
         foreach ($calocns as $k=>$v) print "$k = $v\n";
     } else {
         print "You've not configured your openssl installation on this host\n";
     }

     print "\nIf all good so far, then this bit should work....\n";
     print "fsockopen\n";
     var_dump(fsockopen("ssl://smtp.gmail.com", 465, $errno, $errstr, 3.0));
     var_dump($errno);
     var_dump($errstr);

  • After start dubugging i got below error:

    DNS
    bool(true)
    array(5) {
      [0]=>
      string(31) "alt2.gmail-smtp-in.l.google.com"
      [1]=>
      string(26) "gmail-smtp-in.l.google.com"
      [2]=>
      string(31) "alt1.gmail-smtp-in.l.google.com"
      [3]=>
      string(31) "alt4.gmail-smtp-in.l.google.com"
      [4]=>
      string(31) "alt3.gmail-smtp-in.l.google.com"
    }
    IPV4 address = 74.125.137.26

    If you've got this far without errors then problem is with your SSL config
    Check you've got your cacerts deployed in one of the following locations
    default_cert_file = /opt/alt/openssl11/etc/pki/tls/cert.pem
    default_cert_file_env = SSL_CERT_FILE
    default_cert_dir = /opt/alt/openssl11/etc/pki/tls/certs
    default_cert_dir_env = SSL_CERT_DIR
    default_private_dir = /opt/alt/openssl11/etc/pki/tls/private
    default_default_cert_area = /opt/alt/openssl11/etc/pki/tls
    ini_cafile =
    ini_capath =
  • I assume you have already tested if you have network connectivity?

    telnet 74.125.137.26 465

    does that connect? Connection refused suggests a firewall (yours or your ISP) blocking the port...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion