PHPMailer library SMTP class blocked



Hello everybody. Trying to make my script send mail messages via Gmail using PHPMailer, but it fails everytime with an error “SMTP connect() failed.” PHPMailer troubleshooting wiki on Github says on this case: “This is often reported as a PHPMailer problem, but it’s almost always down to local DNS failure, firewall blocking or other issue on your local network. It means that PHPMailer is unable to contact the SMTP server you have specified in the Host property, but doesn’t say exactly why.”

Here is the code fragment regarding PHPMailer:

            // instantiate mailer
            $mail = new PHPMailer();
            //required for gmail
            $mail->SMTPAuth   = true;
            $mail->Host = "";
            // login to gmail
            $mail->Username   = "username";
            // password to gmail
            $mail->Password   = "password";
            //required for gmail
            $mail->SMTPSecure = "tls"; 
            $mail->Port = 587;
            // set From:
            // set To:
            // set Subject:
            $mail->Subject = "Subject";
            // set body
            $mail->Body = "Text";
            // set alternative body, in case user's mail client doesn't support HTML
            $mail->AltBody = "AltText";
            $mail->SMTPdebug = 4;
            // send mail
            if ($mail->Send() === false)
                die($mail->ErrorInfo . "\n");


I don’t think it is possible to access PHP native mailing in C9 - the way I got around it was using a third party smtp provider - I used mandrill (unfortunately it is not free anymore…). There are others I think, it is a lot of messing around and I wish C9 would make it easier somehow…


Yes, you’re right (( The only way I managed to send e-mail messages is posting directly to SendGrid API with curl():

$mail = curl_init("");

$message = "<html> 
                                    Message text here
                $params = array(
                    'api_user'  => "SendGrid username",
                    'api_key'   => "SendGrid password",
                    'to'        => $realmail,
                    'toname'    => $username,
                    'subject'   => "Subject",
                    'html'      => $message,
                    'fromname'  => 'FromName',
                    'replyto'   => "",
                    'from'      => "",
                curl_setopt($mail, CURLOPT_POST, true);
                curl_setopt($mail, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($mail, CURLOPT_POSTFIELDS, $params);
                curl_setopt($mail, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1_2');
                $response = curl_exec($mail);

    if (!$response) 
        echo "Error: " . curl_error($mail);