trying to send mail using swift mailer, gmail smtp, php

后端 未结 8 1226
攒了一身酷
攒了一身酷 2020-12-01 01:08

Here is my code:

setUs         


        
相关标签:
8条回答
  • 2020-12-01 01:39

    GMail's SMTP requires encryption. Use:

    Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl");
    
    0 讨论(0)
  • 2020-12-01 01:43

    I got same error before and i added "ssl" parameter in Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl") like osos said.

    IT WORKS!! thanks..:D

    this is my code:

    <?php
    require_once 'swift/lib/swift_required.php';
    
    $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
      ->setUsername('XXXXXXX@gmail.com')
      ->setPassword('XXXXXXX');
    
    $mailer = Swift_Mailer::newInstance($transport);
    $message = Swift_Message::newInstance('THIS IS THE SUBJECT')
      ->setFrom(array('XXXXXXX@gmail.com' => 'YOUR NAME'))
      ->setTo(array('XXXXXXX@gmail.com' => 'YOU'))
      ->setBody('This is the text of the mail send by Swift using SMTP transport.');
    //$attachment = Swift_Attachment::newInstance(file_get_contents('path/logo.png'), 'logo.png');  
    //$message->attach($attachment);
    $numSent = $mailer->send($message);
    printf("Sent %d messages\n", $numSent);
    ?>
    
    0 讨论(0)
提交回复
热议问题