php smtp 发送邮件_如何在PHP中使用SMTP发送邮件

php smtp 发送邮件

SwiftMailer Logo

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 发送邮件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值