Sending mails in PHP using Yahoo SMTP

前端 未结 4 1046
走了就别回头了
走了就别回头了 2021-01-13 15:46

How can I send an email via Yahoo!\'s SMTP servers in PHP?

4条回答
  •  走了就别回头了
    2021-01-13 16:04

    You should use something like Swift Mailer or PHPMailer. The following example is for Swift:

    $message = Swift_Message::newInstance()
      ->setSubject('Your subject')
      ->setFrom(array('john@doe.com' => 'John Doe'))
      ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
      ->setBody('Here is the message itself')
      ->addPart('Here is the message itself', 'text/html')
    ;
    
    $transport = Swift_SmtpTransport::newInstance('smtp.mail.yahoo.com', 465, 'ssl')
      ->setUsername('your username')
      ->setPassword('your password')
    ;
    
    $mailer = Swift_Mailer::newInstance($transport);
    
    $result = $mailer->send($message);
    

提交回复
热议问题