Are there alternative methods to sending bulk emails in PHP without using a mailing list provided by the hosting provider?
Sending bulk emails in PHP without using a mailing list provided by the hosting provider can be achieved by utilizing third-party email delivery services such as SendGrid, Mailgun, or Amazon SES. These services offer APIs that can be integrated into your PHP code to send bulk emails efficiently and reliably.
// Example code using SendGrid API to send bulk emails
require 'vendor/autoload.php'; // Include SendGrid PHP library
$apiKey = 'YOUR_SENDGRID_API_KEY';
$sg = new \SendGrid($apiKey);
$from = new \SendGrid\Email("Sender Name", "sender@example.com");
$subject = "Subject of the email";
$content = new \SendGrid\Content("text/plain", "Body of the email");
$mail = new \SendGrid\Mail($from, $subject, $to, $content);
// Add recipients to the email
$to = ["recipient1@example.com", "recipient2@example.com"];
foreach ($to as $email) {
$personalization = new \SendGrid\Personalization();
$personalization->addTo(new \SendGrid\Email(null, $email));
$mail->addPersonalization($personalization);
}
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
echo $response->body();