php smtp 发送邮件
![swiftmailer-logo SwiftMailer Logo](https://i-blog.csdnimg.cn/blog_migrate/82ff0bf6866d2807a8c03308f1495155.gif)
You have two primary choices that you can use: SwiftMailer library or the PHP Extension and Application Repository (PEAR). To use SwiftMailer, here is an example (although their documentation describes in more detail the individual methods, etc.)
您可以使用两个主要选择: SwiftMailer库或PHP扩展和应用程序存储库( PEAR )。 要使用SwiftMailer,这是一个示例(尽管他们的文档更详细地描述了各个方法等)。
$transport = Swift_SmtpTransport::newInstance(‘mail.example.com’, 587); // your mail server address and port. If you don’t know what yours is, go to cPanel -> E-mail Settings and for the specific e-mail account, More -> Configure E-mail Client – it will be displayed there.
$ transport = Swift_SmtpTransport :: newInstance('mail.example.com',587); //您的邮件服务器地址和端口。 如果您不知道自己的身份,请转到cPanel->电子邮件设置,对于特定的电子邮件帐户,更多->配置电子邮件客户端-将显示在此处。
$mailer = Swift_Mailer::newInstance($transport); // creates new instance of an SMTP transport specifically
$ mailer = Swift_Mailer :: newInstance($ transport); //专门创建SMTP传输的新实例
$transport->setUsername(’[email protected]’); $transport->setPassword(‘your_password_here’);
$ transport-> setUsername(' [受电子邮件保护] '); $ transport-> setPassword('your_password_here');
$message = Swift_Message::newInstance(); $message->setSubject(‘Set the subject of the e-mail’); $message->setFrom(array(’[email protected]’ => ‘Your Name/Company Name’)); $message->setTo(array($email)); $message->addPart(‘<p>If you want <b>HTML in your e-mail use addPart()</b></p>’, ‘text/html’);
$ message = Swift_Message :: newInstance(); $ message-> setSubject('设置电子邮件的主题'); $ message-> setFrom(array(' [受电子邮件保护] '=>'您的姓名/公司名称')); $ message-> setTo(array($ email)); $ message-> addPart('<p>如果要在电子邮件中使用<b> HTML,请使用addPart()</ b> </ p>','text / html');
$result = $mailer->send($message); // returns FALSE boolean on failure
$ result = $ mailer-> send($ message); //失败时返回FALSE布尔值
if(!$result) { echo ‘failure’; } else { echo ‘success’; }
if(!$ result){echo'失败'; } else {echo'success'; }
翻译自: https://www.eukhost.com/blog/webhosting/how-to-send-mail-using-smtp-in-php/
php smtp 发送邮件