1

I am unable to send mail using localhost connection and correct code . But getting this error

Zend\Mail\Protocol\Exception\RuntimeException

File:

/var/www/html/rustagi/vendor/ZF2/library/Zend/Mail/Protocol/AbstractProtocol.php:348

Message:

5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsl
 5.7.14 6EWOp6ZKxNQid3Q84gVgHX7gRcrLH3FRL88s1Y-aurZXgnxEziLaRJrbc2OxtCgugbO98W
 5.7.14 CMXNsqYvCG5EwG5iP9GU2N3NErFFURRUqffsIRCJW_u7_4WdRXu_Rb1mZjTITQm8VexWbn
 5.7.14 tDk2rYv_9cv7NAcQUi5eItDC9HhF0mKns_yLRj1Rsl3nz0sQmn0rtfiJkg_mF8hQelwSAZ
 5.7.14 F943KqTxTU3tWiZzO54KNZdUd3YWI> Please log in via your web browser and
 5.7.14 then try again.
 5.7.14  Learn more at
 5.7.14  https://support.google.com/mail/answer/78754 tn5sm2706283pac.32 - gsmtp

Stack trace:

#0 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mail/Protocol/Smtp/Auth/Login.php(83): Zend\Mail\Protocol\AbstractProtocol->_expect(235)
#1 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mail/Protocol/Smtp.php(193): Zend\Mail\Protocol\Smtp\Auth\Login->auth()
#2 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mail/Transport/Smtp.php(340): Zend\Mail\Protocol\Smtp->helo('localhost')
#3 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mail/Transport/Smtp.php(325): Zend\Mail\Transport\Smtp->connect()
#4 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mail/Transport/Smtp.php(336): Zend\Mail\Transport\Smtp->lazyLoadConnection()
#5 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mail/Transport/Smtp.php(205): Zend\Mail\Transport\Smtp->connect()
#6 /var/www/html/rustagi/module/ZfcAdmin/src/ZfcAdmin/Controller/AdminController.php(185): Zend\Mail\Transport\Smtp->send(Object(Zend\Mail\Message))
#7 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mvc/Controller/AbstractActionController.php(83): ZfcAdmin\Controller\AdminController->SendMailAction()
#8 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#9 /var/www/html/rustagi/vendor/ZF2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#10 /var/www/html/rustagi/vendor/ZF2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#13 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#14 /var/www/html/rustagi/vendor/ZF2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#15 /var/www/html/rustagi/vendor/ZF2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 /var/www/html/rustagi/vendor/ZF2/library/Zend/Mvc/Application.php(313): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 /var/www/html/rustagi/index.php(17): Zend\Mvc\Application->run()
#18 {main}

I am using this code :-

$options = new Mail\Transport\SmtpOptions(array(  
        'name' => 'localhost',  
        'host' => 'smtp.gmail.com',  
        'port'=> 587,  
        'connection_class' => 'login',  
        'connection_config' => array(  
            'username' => 'someone@gmail.com',  
            'password' => '********',  
            'ssl'=> 'tls',  
        ),  
));  

$fileContents = fopen("/usr/share/pixmaps/faces/sky.jpg", 'r');
$attachment = new Mime\Part($fileContent);
$attachment->type = 'image/jpg';
$attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;

// $this->renderer = $this->getServiceLocator()->get('ViewRenderer');  
$content = "gdgdfgdfgdfgddfg";  

// make a header as html  
$html = new MimePart($content);  
$html->type = "text/html";  
$body = new MimeMessage();  
$body->setParts(array($html,$attachment));  

// instance mail   
$mail = new Mail\Message();  
$mail->setBody($body); // will generate our code html from template.phtml  
$mail->setFrom('someone@gmail.com','Sender Name');  
$mail->setTo('someone1@gmail.com');  
$mail->setSubject('Your Subject');  

$transport = new Mail\Transport\Smtp($options);  
$transport->send($mail);

How can i achieve this .I've searched alot on this but getting no solution for this your help will be highly appriciated thanx.

php devp
  • 75
  • 3
  • 12

4 Answers4

1

Sorry if i'm digging up this subject but i got the same problem. The send function seems to not works but there is no error message...

Here is a part of my code:

        $mail = new Mail\Message();
        $options = new Mail\Transport\SmtpOptions(array(  
        'name' => 'localhost',  
        'host' => 'smtp.gmail.com',  
        'port'=> 465,  
        'connection_class' => 'login',  
        'connection_config' => array(  
            'username' => 'someone@gmail.com',  
            'password' => '***',  
            'ssl'=> 'ssl',  
        ),  
    )); 
    $mail->setBody("This is the text of the email");
    $mail->setFrom('noreply@reims.fr','Ecole Municipal des Sports');
    $mail->addTo('someone@gmail.com');
    $mail->setSubject('Inscription annulée');
    $transport = new Mail\Transport\Sendmail('someone@gmail.com',$options);
    $transport->send($mail);
    var_dump($mail);
    var_dump($transport);
    var_dump($transport->send($mail));
skywalskurt
  • 87
  • 1
  • 10
0

change line

'ssl'=> 'tls' // tls causes problems when sending via gmail

to

'ssl'=> 'ssl'

be sure that in the configuration ini there is no overwriting entry

smtp.params.ssl = "tls" // this is bad -> tls causes problems when sending via gmail
Alexis Peters
  • 1,583
  • 1
  • 10
  • 17
0

Nothing to do with TLS. You should also allow less secure apps through your gmail account here. Worked for me..!!

Ritesh
  • 4,720
  • 6
  • 27
  • 41
-2

see your configuration is false using ssl or tls? i suggest to you using phpmailer script

first active SMTP service from php.ini

search: [mail function]

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

and next time you must using PHPMailer class ~> Download PHPMailer

template function:

Use this ↓

<?php
    require_once ("PHPMailer/class.phpmailer.php");
    $mail = new PHPMailer(true);
    $mail->isSMTP();

   try{
    $mail->host = "smtp@gmail.com";
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "ssl";
    $mail->Port = 465;
    $mail->Username = "username@email.com";
    $mail->Password = "yourPassword";
    $mail->AddAddress("target@email.com");
    $mail->SetForm("yourMail@Email.com","your name");
    $mail->Subject = "emailSubject";
    $mail->CharSet = "UTF-8";
    $mail->ContentType = "text/htm";
    $mail->msgHTML("MailContent");
    $mail->send();
        echo 'Seccess';

    }
   catch(phpmailerException $mail){
    echo $mail->errorMessage();
    }
    catch(Exception $mail){
        echo $mail->getMessage();
    }
?>
Mass log
  • 15
  • 3