简体   繁体   English

用PHP发送电子邮件

[英]Sending emails in PHP

I am creating a website using bootstrap, HTML and PHP. 我正在使用引导程序,HTML和PHP创建一个网站。 Whenever I am sending emails via mail function, many recipients are unable to receive the email as my host told me that using a php mailer on a shared server like SH-2499957 is not a good idea. 每当我通过邮件功能发送电子邮件时,许多收件人都无法接收电子邮件,因为我的主人告诉我,在像SH-2499957这样的共享服务器上使用php邮件程序不是一个好主意。 What other options do I have to send emails through PHP, that would not cause this problem? 我还需要通过PHP发送电子邮件的其他哪些选项,而不会导致此问题呢?

Try an external service like SendGrid . 尝试使用诸如SendGrid之类的外部服务。 I know that SendGrid provides a PHP library for easy integration as well as through SMTP and a web API. 我知道SendGrid提供了一个易于集成的PHP库,并通过SMTP和Web API进行了集成。 They also provide 12,000 free emails per month. 他们还每月提供12,000封免费电子邮件。

SendGrid example : SendGrid示例

// using SendGrid's PHP Library - https://github.com/sendgrid/sendgrid-php
$sendgrid = new SendGrid($api_user, $api_key);
$email    = new SendGrid\Email();

$email->addTo("test@sendgrid.com")
      ->setFrom("you@youremail.com")
      ->setSubject("Sending with SendGrid is Fun")
      ->setHtml("and easy to do anywhere, even with PHP");

$sendgrid->send($email);

From https://sendgrid.com/ https://sendgrid.com/

Other alternatives include MailChimp , RailGun , AWS SES , and MailJet . 其他替代方案包括MailChimpRailGunAWS SESMailJet

Use the Mandrill API, you can track your mails(Sent, Bounced, Delivered etc.), statistics and all. 使用Mandrill API,您可以跟踪邮件(已发送,退回,已发送等),统计信息以及所有信息。 Add Templates with Ease. 轻松添加模板。 Check the documentation here 此处查看文档

I just signed up for Mailgun and it's a great resource for developers. 我刚刚注册了Mailgun ,它对开发人员来说是一个很好的资源。 10,000 free emails per month, easy setup, great API, one less attack vector on your server, and your outgoing emails are way less likely to go to spam. 每月有10,000封免费电子邮件,易于设置,强大的API,服务器上的攻击向量减少了一半,外发电子邮件被垃圾邮件的可能性也降低了。 I have an existing mail server that works great but I'm in the process of switching over because mails sent through the cloud tend to have a higher open rate. 我有一个运行良好的现有邮件服务器,但由于通过云发送的邮件的打开率较高,因此我正在切换。

Mailgun Example for PHP: PHP的Mailgun示例

$mailgun->sendMessage("mail.example.com",[
'from'    => 'Your Company <noreply@mailgun.net>',
'to'      => 'Excited User <example@mailgun.net>',
'subject' => 'Hello World',
'text'    => 'Testing some Mailgun awesomeness!']);

You can use Gmail (or any other SMTP-compatible email provider) with PHPMailer library. 您可以将Gmail(或任何其他SMTP兼容的电子邮件提供程序)与PHPMailer库一起使用。 Consider that you can't use services like Gmail to broadcast a large number of emails. 考虑到您不能使用Gmail之类的服务来广播大量电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM