From 8cecc908fbddedf961420d38bf8c0c3acde51049 Mon Sep 17 00:00:00 2001 From: Zeno Kerr Date: Tue, 10 Dec 2024 11:15:56 +0100 Subject: [PATCH 1/6] Add some information about sending emails from PHP Fixes #1085 --- .../php/2000-01-01-sending-emails.md | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/_posts/languages/php/2000-01-01-sending-emails.md diff --git a/src/_posts/languages/php/2000-01-01-sending-emails.md b/src/_posts/languages/php/2000-01-01-sending-emails.md new file mode 100644 index 000000000..806f379f7 --- /dev/null +++ b/src/_posts/languages/php/2000-01-01-sending-emails.md @@ -0,0 +1,51 @@ +--- +title: Sending emails from PHP +nav: Sending Emails +modified_at: 2024-12-10 10:45:00 +tags: php email phpmailer smtp mail +index: 100 +--- + +For sending emails from your php application you will need to send via an external smtp server. +Several options are listed on our [dedicated section]({% post_url platform/app/2000-01-01-sending-emails %}). + +You can use a mailing library such as [PHPMailer](https://github.com/PHPMailer/PHPMailer) (or equivalent) to send from your PHP application, via an external SMTP server. + +### Example using PHPMailer via Brevo + +```php +isSMTP(); + $mail->Host = 'smtp-relay.brevo.com'; + $mail->SMTPAuth = true; + $mail->Username = 'YOUR_BREVO_USERNAME'; + $mail->Password = 'YOUR_BREVO_PASSWORD'; + $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; + $mail->Port = 587; + + // Recipients + $mail->setFrom('from@example.com', 'Sender Name'); + $mail->addAddress('recipient@example.com', 'Recipient Name'); + $mail->addReplyTo('reply@example.com', 'Reply Name'); + + // Content + $mail->isHTML(true); + $mail->Subject = 'Test Email from PHPMailer using Brevo'; + $mail->Body = '

This is a test email sent using PHPMailer with Brevo SMTP.

'; + $mail->AltBody = 'This is a test email sent using PHPMailer with Brevo SMTP.'; + + $mail->send(); + echo 'Message has been sent'; +} catch (Exception $e) { + echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; +} +``` \ No newline at end of file From f217d8ef8341a2cb04b84be1283067742ab570d5 Mon Sep 17 00:00:00 2001 From: sc-zenokerr Date: Wed, 11 Dec 2024 15:31:00 +0100 Subject: [PATCH 2/6] Update src/_posts/languages/php/2000-01-01-sending-emails.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Étienne M. --- src/_posts/languages/php/2000-01-01-sending-emails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_posts/languages/php/2000-01-01-sending-emails.md b/src/_posts/languages/php/2000-01-01-sending-emails.md index 806f379f7..924ad2da3 100644 --- a/src/_posts/languages/php/2000-01-01-sending-emails.md +++ b/src/_posts/languages/php/2000-01-01-sending-emails.md @@ -6,7 +6,7 @@ tags: php email phpmailer smtp mail index: 100 --- -For sending emails from your php application you will need to send via an external smtp server. +For sending emails from your PHP application you will need to send via an external SMTP server. Several options are listed on our [dedicated section]({% post_url platform/app/2000-01-01-sending-emails %}). You can use a mailing library such as [PHPMailer](https://github.com/PHPMailer/PHPMailer) (or equivalent) to send from your PHP application, via an external SMTP server. From 93997c27da8a25a2769f8e722dbcfff2bedb2809 Mon Sep 17 00:00:00 2001 From: sc-zenokerr Date: Wed, 11 Dec 2024 15:31:27 +0100 Subject: [PATCH 3/6] Update src/_posts/languages/php/2000-01-01-sending-emails.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Étienne M. From f6dc42f5e8631cb7dc6bea1fb3de7b142825bd1b Mon Sep 17 00:00:00 2001 From: Zeno Kerr Date: Fri, 13 Dec 2024 09:46:39 +0100 Subject: [PATCH 4/6] Remove the Brevo code example. --- .../php/2000-01-01-sending-emails.md | 44 ++----------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/src/_posts/languages/php/2000-01-01-sending-emails.md b/src/_posts/languages/php/2000-01-01-sending-emails.md index 924ad2da3..f6a332f2d 100644 --- a/src/_posts/languages/php/2000-01-01-sending-emails.md +++ b/src/_posts/languages/php/2000-01-01-sending-emails.md @@ -6,46 +6,8 @@ tags: php email phpmailer smtp mail index: 100 --- -For sending emails from your PHP application you will need to send via an external SMTP server. +For sending emails from your PHP application you will need to send via an external SMTP server. Several options are listed on our [dedicated section]({% post_url platform/app/2000-01-01-sending-emails %}). -You can use a mailing library such as [PHPMailer](https://github.com/PHPMailer/PHPMailer) (or equivalent) to send from your PHP application, via an external SMTP server. - -### Example using PHPMailer via Brevo - -```php -isSMTP(); - $mail->Host = 'smtp-relay.brevo.com'; - $mail->SMTPAuth = true; - $mail->Username = 'YOUR_BREVO_USERNAME'; - $mail->Password = 'YOUR_BREVO_PASSWORD'; - $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; - $mail->Port = 587; - - // Recipients - $mail->setFrom('from@example.com', 'Sender Name'); - $mail->addAddress('recipient@example.com', 'Recipient Name'); - $mail->addReplyTo('reply@example.com', 'Reply Name'); - - // Content - $mail->isHTML(true); - $mail->Subject = 'Test Email from PHPMailer using Brevo'; - $mail->Body = '

This is a test email sent using PHPMailer with Brevo SMTP.

'; - $mail->AltBody = 'This is a test email sent using PHPMailer with Brevo SMTP.'; - - $mail->send(); - echo 'Message has been sent'; -} catch (Exception $e) { - echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; -} -``` \ No newline at end of file +You can use a mailing library such as [PHPMailer](https://github.com/PHPMailer/PHPMailer) (or equivalent) to send from +your PHP application via an external SMTP server. From a471257f1d9fa26a8acbcbb6a2069163fc9eccd8 Mon Sep 17 00:00:00 2001 From: Zeno Kerr Date: Fri, 13 Dec 2024 09:49:29 +0100 Subject: [PATCH 5/6] Revert "Remove the Brevo code example." This reverts commit f6dc42f5e8631cb7dc6bea1fb3de7b142825bd1b. --- .../php/2000-01-01-sending-emails.md | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/_posts/languages/php/2000-01-01-sending-emails.md b/src/_posts/languages/php/2000-01-01-sending-emails.md index f6a332f2d..924ad2da3 100644 --- a/src/_posts/languages/php/2000-01-01-sending-emails.md +++ b/src/_posts/languages/php/2000-01-01-sending-emails.md @@ -6,8 +6,46 @@ tags: php email phpmailer smtp mail index: 100 --- -For sending emails from your PHP application you will need to send via an external SMTP server. +For sending emails from your PHP application you will need to send via an external SMTP server. Several options are listed on our [dedicated section]({% post_url platform/app/2000-01-01-sending-emails %}). -You can use a mailing library such as [PHPMailer](https://github.com/PHPMailer/PHPMailer) (or equivalent) to send from -your PHP application via an external SMTP server. +You can use a mailing library such as [PHPMailer](https://github.com/PHPMailer/PHPMailer) (or equivalent) to send from your PHP application, via an external SMTP server. + +### Example using PHPMailer via Brevo + +```php +isSMTP(); + $mail->Host = 'smtp-relay.brevo.com'; + $mail->SMTPAuth = true; + $mail->Username = 'YOUR_BREVO_USERNAME'; + $mail->Password = 'YOUR_BREVO_PASSWORD'; + $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; + $mail->Port = 587; + + // Recipients + $mail->setFrom('from@example.com', 'Sender Name'); + $mail->addAddress('recipient@example.com', 'Recipient Name'); + $mail->addReplyTo('reply@example.com', 'Reply Name'); + + // Content + $mail->isHTML(true); + $mail->Subject = 'Test Email from PHPMailer using Brevo'; + $mail->Body = '

This is a test email sent using PHPMailer with Brevo SMTP.

'; + $mail->AltBody = 'This is a test email sent using PHPMailer with Brevo SMTP.'; + + $mail->send(); + echo 'Message has been sent'; +} catch (Exception $e) { + echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; +} +``` \ No newline at end of file From 9a1dce292ec3e94de0a12d1cb608eca093dc2fef Mon Sep 17 00:00:00 2001 From: Zeno Kerr Date: Fri, 13 Dec 2024 09:50:32 +0100 Subject: [PATCH 6/6] Reinstate the Brevo example (and use environment variables for the credentials) --- src/_posts/languages/php/2000-01-01-sending-emails.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_posts/languages/php/2000-01-01-sending-emails.md b/src/_posts/languages/php/2000-01-01-sending-emails.md index 924ad2da3..a743c59da 100644 --- a/src/_posts/languages/php/2000-01-01-sending-emails.md +++ b/src/_posts/languages/php/2000-01-01-sending-emails.md @@ -27,8 +27,8 @@ try { $mail->isSMTP(); $mail->Host = 'smtp-relay.brevo.com'; $mail->SMTPAuth = true; - $mail->Username = 'YOUR_BREVO_USERNAME'; - $mail->Password = 'YOUR_BREVO_PASSWORD'; + $mail->Username = getenv('BREVO_USERNAME'); + $mail->Password = getenv('BREVO_PASSWORD'); $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587;