![]() |
Admin 1/16/2021 |
We use SendGrid to send some of our emails. We use SMTP for single emails and they have a web-based UI that helps you to prepare and send a newsletter to the list of subscribers. Never really used they REST API but here is the link: https://sendgrid.com/docs/api-reference/ |
D
|
david22585 author 1/16/2021 |
We use SendGrid to send some of our emails. We use SMTP for single emails and they have a web-based UI that helps you to prepare and send a newsletter to the list of subscribers. Never really used they REST API but here is the link: https://sendgrid.com/docs/api-reference/ Check 'MAIL SEND' link on the left for the easiest example of email sending, they provide the sample PHP code as well. PS. Never heard of web hosting companies blocking external for spam reasons. Usually, it is the other way around. Some people may open an account to send spam through their SMTP. External SMTP is someone else's problem.
You cannot use external SMTP servers to send e-mail messages if you have one of the following hosting packages: Web hosting (Startup, Drive, Turbo Boost, or Turbo Max) Reseller hosting Managed WordPress hosting
|
A
|
acpan 1/16/2021 |
Most hosting providers worry their IP ranges are blocked or blacklisted automatically by SPAM detection Providers, especially people who request to open emails ports, if you host your email servers on your host and need to open email ports to communicate with other email servers in the world. If you are not careful, the IP will be blacklisted within hours after spam detected from your host, and it is done by SPAM detection "robots" automatically. So Providers are pretty paranoid about email ports, because they will have less IPs to provide.
|
D
|
david22585 author 2/7/2021 |
Most hosting providers worry their IP ranges are blocked or blacklisted automatically by SPAM detection Providers, especially people who request to open emails ports, if you host your email servers on your host and need to open email ports to communicate with other email servers in the world. If you are not careful, the IP will be blacklisted within hours after spam detected from your host, and it is done by SPAM detection "robots" automatically. So Providers are pretty paranoid about email ports, because they will have less IPs to provide. Just for sending out via SMTP (without receiving emails) should be fine. However, my experience is, they (at least 2 to 3 providers i used) even blocked the remote SMTP server port 25 and other email ports from my hosts, until I requested and acknowledged their anti-spamming agreement. You can check if your IP or any port, domain is blocked/blacklisted using, eg. mxtoolbox.com This is always the first thing i check, when i create a new cloud instance. I will recreate if the assigned IP is blacklisted in mxtoolbox. On using the Email API Provider, I tried SendGrid and MailJet, they have both SMTP and REST API. API wise, it is just like sending a PHP Curl. I would normally submit from the PHP Web page (eg. PHPRunner generated site) that sends CLI (Linux) command to a PHP script (sendmail.php) that runs in the background, so that it will not freeze the web page if it takes too long. Below is a sample script just to give you an idea, that i put in my host to receive my email task, the script is also available at the online help once you have an account with them. You should also put in place security measures, like restricting the IP or login session:
|
A
|
acpan 2/7/2021 |
>>It says that we can use PHP code in events, but this code throws an error: Parse error: syntax error, unexpected 'use' (T_USE) in .......
|
D
|
david22585 author 2/7/2021 |
>>It says that we can use PHP code in events, but this code throws an error: Parse error: syntax error, unexpected 'use' (T_USE) in ....... First you should do a simple isolated test, drop in the sample scripts into your web server, make a simple test page, and send email. If "use" error persist, you likely did not load the library correctly.
$email = new \SendGrid\Mail\Mail();
Fatal error: Uncaught exception 'SendGrid\Mail\TypeException' with message '"$toEmails" must be an array. Got: ["email1@mail.com" => "Name 1", "email2@mail.com" => "Name 2", "email3@test.com" => "Name 3"]'
|
A
|
acpan 2/8/2021 |
Seems your array is not form correctly as what SendGrid expects. |
A
|
acpan 2/8/2021 |
Try this:
|
D
|
david22585 author 2/8/2021 |
Try this:
require_once(getabspath("include/sendgrid/sendgrid-php.php"));
|
A
|
acpan 2/8/2021 |
Great!
|
D
|
david22585 author 2/20/2021 |
Just wanted to add another one in for others to reference, or for others to build off of to maybe make it better. I didn't want to use the BCC method. I tried many times to make it work to where individual emails were sent and it didn't show the other peoples e-mail addresses. I couldn't get the sendmail examples to work, but I did get it to work by going through a loop for each email queried. I know this probably takes longer, and I hope that others can maybe build from this and add to it to make it better.
|