Email API for PHP
Send Email with our API for PHP easily and securely. Try our API for PHP for free. Our team will help you to integrate the automated sending of emails and Email Marketing campaigns in your application in PHP.
Email API functionality
Send email with PHP
<?
$class="email";
$method="sendemail";
$user="user";
$password="password";
$subject="Afilnet - Test email";
$to="test@test.com";
$email="email+test";
$attachments="[{\"url\":\"https://test.com/test1.pdf\",\"name\":\"Test 1\"},{\"url\":\"https://test.com/test2.pdf\",\"name\":\"Test 2\"}]";
$scheduledatetime="";
$output="";
$result = file_get_contents("https://www.afilnet.com/api/http/?class=".$class."&method=".$method."&user=".$user."&password=".$password."&subject=".$subject."&to=".$to."&email=".$email."&attachments=".$attachments."&scheduledatetime=".$scheduledatetime."&output=".$output);
?>
<?
$url = "https://www.afilnet.com/api/http/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("sendemail"),
"user" => urlencode("user"),
"password" => urlencode("password"),
"subject" => urlencode("Afilnet - Test email"),
"to" => urlencode("test@test.com"),
"email" => urlencode("email+test"),
"attachments" => urlencode("[{\"url\":\"https://test.com/test1.pdf\",\"name\":\"Test 1\"},{\"url\":\"https://test.com/test2.pdf\",\"name\":\"Test 2\"}]"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<?
$url = "https://www.afilnet.com/api/basic/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("sendemail"),
"subject" => urlencode("Afilnet - Test email"),
"to" => urlencode("test@test.com"),
"email" => urlencode("email+test"),
"attachments" => urlencode("[{\"url\":\"https://test.com/test1.pdf\",\"name\":\"Test 1\"},{\"url\":\"https://test.com/test2.pdf\",\"name\":\"Test 2\"}]"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERPWD, $user.":".$password);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 401)
{
// LOGIN ERROR
} else {
// SUCCESS LOGIN
}
?>
<?
# This example requires nusoap
require_once('nusoap.php');
$class="email";
$method="sendemail";
$user="user";
$password="password";
$subject="Afilnet - Test email";
$to="test@test.com";
$email="email+test";
$attachments="[{\"url\":\"https://test.com/test1.pdf\",\"name\":\"Test 1\"},{\"url\":\"https://test.com/test2.pdf\",\"name\":\"Test 2\"}]";
$scheduledatetime="";
$output="";
# Create SOAP Client
$soapclient = new soapclient('https://www.afilnet.com/api/soap/index.php?wsdl');
# Call to method
$result = $soapclient->call($user, $password, $class, $method, '{"subject":"'.$subject.'","to":"'.$to.'","email":"'.$email.'","attachments":"'.$attachments.'","scheduledatetime":"'.$scheduledatetime.'","output":"'.$output.'"}');
?>
Parameter | Description | Compulsory / Optional |
---|---|---|
class=email | Class requested: Class to which the request is made | Compulsory |
method=sendemail | Class method requested: Method of the class to which the request is made | Compulsory |
user | User and e-mail of your Afilnet account | Compulsory |
password | Password of your Afilnet account | Compulsory |
subject | Sender ID | Compulsory |
to | Destination email | Compulsory |
Email message to be sent | Compulsory | |
attachments | JSON que contiene la lista de archivos con los campos (name, url) que se enviarán adjuntos | Optional |
scheduledatetime | Delivery date and time in yyyy-mm-dd hh:mm:ss format | Optional |
output | Output format of the result | Optional |
Answer:
- status
-
result (if status=success), here you will receive the following values:
- messageid
- credits
- error (if status=error), here you will receive the error code
Error codes:
Code | Description |
---|---|
MISSING_USER | User or email not included |
MISSING_PASSWORD | Password not included |
MISSING_CLASS | Class not included |
MISSING_METHOD | Method not included |
MISSING_COMPULSORY_PARAM | Compulsory parameter not included |
INCORRECT_USER_PASSWORD | Incorrect user or password |
INCORRECT_CLASS | Incorrect class |
INCORRECT_METHOD | Incorrect method |
NO_ROUTE_AVAILABLE | There are no available paths for the indicated destination |
NO_CREDITS | Your balance is insufficient |
Send email from template with PHP
<?
$class="email";
$method="sendemailfromtemplate";
$user="user";
$password="password";
$to="34600000000";
$idtemplate=1000;
$params="mobile:123456789,name:test+name";
$scheduledatetime="";
$output="";
$result = file_get_contents("https://www.afilnet.com/api/http/?class=".$class."&method=".$method."&user=".$user."&password=".$password."&to=".$to."&idtemplate=".$idtemplate."¶ms=".$params."&scheduledatetime=".$scheduledatetime."&output=".$output);
?>
<?
$url = "https://www.afilnet.com/api/http/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("sendemailfromtemplate"),
"user" => urlencode("user"),
"password" => urlencode("password"),
"to" => urlencode("34600000000"),
"idtemplate" => urlencode(1000),
"params" => urlencode("mobile:123456789,name:test+name"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<?
$url = "https://www.afilnet.com/api/basic/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("sendemailfromtemplate"),
"to" => urlencode("34600000000"),
"idtemplate" => urlencode(1000),
"params" => urlencode("mobile:123456789,name:test+name"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERPWD, $user.":".$password);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 401)
{
// LOGIN ERROR
} else {
// SUCCESS LOGIN
}
?>
<?
# This example requires nusoap
require_once('nusoap.php');
$class="email";
$method="sendemailfromtemplate";
$user="user";
$password="password";
$to="34600000000";
$idtemplate=1000;
$params="mobile:123456789,name:test+name";
$scheduledatetime="";
$output="";
# Create SOAP Client
$soapclient = new soapclient('https://www.afilnet.com/api/soap/index.php?wsdl');
# Call to method
$result = $soapclient->call($user, $password, $class, $method, '{"to":"'.$to.'","idtemplate":"'.$idtemplate.'","params":"'.$params.'","scheduledatetime":"'.$scheduledatetime.'","output":"'.$output.'"}');
?>
Parameter | Description | Compulsory / Optional |
---|---|---|
class=email | Class requested: Class to which the request is made | Compulsory |
method=sendemailfromtemplate | Class method requested: Method of the class to which the request is made | Compulsory |
user | User and e-mail of your Afilnet account | Compulsory |
password | Password of your Afilnet account | Compulsory |
to | Destination email | Compulsory |
idtemplate | Template identifier | Compulsory |
params | Parameters to be replaced in the template for customization (< |
Optional |
scheduledatetime | Delivery date and time in yyyy-mm-dd hh:mm:ss format | Optional |
output | Output format of the result | Optional |
Answer:
- status
-
result (if status=success), here you will receive the following values:
- messageid
- credits
- error (if status=error), here you will receive the error code
Error codes:
Code | Description |
---|---|
MISSING_USER | User or email not included |
MISSING_PASSWORD | Password not included |
MISSING_CLASS | Class not included |
MISSING_METHOD | Method not included |
MISSING_COMPULSORY_PARAM | Compulsory parameter not included |
INCORRECT_USER_PASSWORD | Incorrect user or password |
INCORRECT_CLASS | Incorrect class |
INCORRECT_METHOD | Incorrect method |
NO_ROUTE_AVAILABLE | There are no available paths for the indicated destination |
NO_CREDITS | Your balance is insufficient |
NOT_ACCESS_TO_TEMPLATE | You haven't access to the selected template |
Send bulk email with PHP
<?
$class="email";
$method="sendemailtogroup";
$user="user";
$password="password";
$subject="Afilnet - Test email";
$idgroup=1;
$email="Afilnet - Test email";
$scheduledatetime="";
$output="";
$result = file_get_contents("https://www.afilnet.com/api/http/?class=".$class."&method=".$method."&user=".$user."&password=".$password."&subject=".$subject."&idgroup=".$idgroup."&email=".$email."&scheduledatetime=".$scheduledatetime."&output=".$output);
?>
<?
$url = "https://www.afilnet.com/api/http/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("sendemailtogroup"),
"user" => urlencode("user"),
"password" => urlencode("password"),
"subject" => urlencode("Afilnet - Test email"),
"idgroup" => urlencode(1),
"email" => urlencode("Afilnet - Test email"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<?
$url = "https://www.afilnet.com/api/basic/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("sendemailtogroup"),
"subject" => urlencode("Afilnet - Test email"),
"idgroup" => urlencode(1),
"email" => urlencode("Afilnet - Test email"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERPWD, $user.":".$password);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 401)
{
// LOGIN ERROR
} else {
// SUCCESS LOGIN
}
?>
<?
# This example requires nusoap
require_once('nusoap.php');
$class="email";
$method="sendemailtogroup";
$user="user";
$password="password";
$subject="Afilnet - Test email";
$idgroup=1;
$email="Afilnet - Test email";
$scheduledatetime="";
$output="";
# Create SOAP Client
$soapclient = new soapclient('https://www.afilnet.com/api/soap/index.php?wsdl');
# Call to method
$result = $soapclient->call($user, $password, $class, $method, '{"subject":"'.$subject.'","idgroup":"'.$idgroup.'","email":"'.$email.'","scheduledatetime":"'.$scheduledatetime.'","output":"'.$output.'"}');
?>
Parameter | Description | Compulsory / Optional |
---|---|---|
class=email | Class requested: Class to which the request is made | Compulsory |
method=sendemailtogroup | Class method requested: Method of the class to which the request is made | Compulsory |
user | User and e-mail of your Afilnet account | Compulsory |
password | Password of your Afilnet account | Compulsory |
subject | Remitente | Compulsory |
idgroup | Identifier of the destination group | Compulsory |
Email message to be sent | Compulsory | |
scheduledatetime | Delivery date and time in yyyy-mm-dd hh:mm:ss format | Optional |
output | Output format of the result | Optional |
Answer:
- status
-
result (if status=success), here you will receive the following values:
- id
- count
- credits
-
destinations
- messageid
- destination
- error (if status=error), here you will receive the error code
Error codes:
Code | Description |
---|---|
MISSING_USER | User or email not included |
MISSING_PASSWORD | Password not included |
MISSING_CLASS | Class not included |
MISSING_METHOD | Method not included |
MISSING_COMPULSORY_PARAM | Compulsory parameter not included |
INCORRECT_USER_PASSWORD | Incorrect user or password |
INCORRECT_CLASS | Incorrect class |
INCORRECT_METHOD | Incorrect method |
NOT_ACCESS_TO_GROUP | You are not allowed into the indicated group |
NO_CREDITS | Your balance is insufficient |
Send bulk email from template with PHP
<?
$class="email";
$method="sendemailtogroupfromtemplate";
$user="user";
$password="password";
$idgroup=1000;
$idtemplate="1000";
$scheduledatetime="";
$output="";
$result = file_get_contents("https://www.afilnet.com/api/http/?class=".$class."&method=".$method."&user=".$user."&password=".$password."&idgroup=".$idgroup."&idtemplate=".$idtemplate."&scheduledatetime=".$scheduledatetime."&output=".$output);
?>
<?
$url = "https://www.afilnet.com/api/http/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("sendemailtogroupfromtemplate"),
"user" => urlencode("user"),
"password" => urlencode("password"),
"idgroup" => urlencode(1000),
"idtemplate" => urlencode("1000"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<?
$url = "https://www.afilnet.com/api/basic/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("sendemailtogroupfromtemplate"),
"idgroup" => urlencode(1000),
"idtemplate" => urlencode("1000"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERPWD, $user.":".$password);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 401)
{
// LOGIN ERROR
} else {
// SUCCESS LOGIN
}
?>
<?
# This example requires nusoap
require_once('nusoap.php');
$class="email";
$method="sendemailtogroupfromtemplate";
$user="user";
$password="password";
$idgroup=1000;
$idtemplate="1000";
$scheduledatetime="";
$output="";
# Create SOAP Client
$soapclient = new soapclient('https://www.afilnet.com/api/soap/index.php?wsdl');
# Call to method
$result = $soapclient->call($user, $password, $class, $method, '{"idgroup":"'.$idgroup.'","idtemplate":"'.$idtemplate.'","scheduledatetime":"'.$scheduledatetime.'","output":"'.$output.'"}');
?>
Parameter | Description | Compulsory / Optional |
---|---|---|
class=email | Class requested: Class to which the request is made | Compulsory |
method=sendemailtogroupfromtemplate | Class method requested: Method of the class to which the request is made | Compulsory |
user | User and e-mail of your Afilnet account | Compulsory |
password | Password of your Afilnet account | Compulsory |
idgroup | Identifier of the destination group | Compulsory |
idtemplate | email.sendemailtogroupfromtemplate_idtemplate | Compulsory |
scheduledatetime | Delivery date and time in yyyy-mm-dd hh:mm:ss format | Optional |
output | Output format of the result | Optional |
Answer:
- status
-
result (if status=success), here you will receive the following values:
- id
- count
- credits
-
destinations
- messageid
- destination
- error (if status=error), here you will receive the error code
Error codes:
Code | Description |
---|---|
MISSING_USER | User or email not included |
MISSING_PASSWORD | Password not included |
MISSING_CLASS | Class not included |
MISSING_METHOD | Method not included |
MISSING_COMPULSORY_PARAM | Compulsory parameter not included |
INCORRECT_USER_PASSWORD | Incorrect user or password |
INCORRECT_CLASS | Incorrect class |
INCORRECT_METHOD | Incorrect method |
NOT_ACCESS_TO_GROUP | You are not allowed into the indicated group |
NO_CREDITS | Your balance is insufficient |
Get email delivery status with PHP
<?
$class="email";
$method="getdeliverystatus";
$user="user";
$password="password";
$messages="123456,123457,123458";
$output="";
$result = file_get_contents("https://www.afilnet.com/api/http/?class=".$class."&method=".$method."&user=".$user."&password=".$password."&messages=".$messages."&output=".$output);
?>
<?
$url = "https://www.afilnet.com/api/http/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("getdeliverystatus"),
"user" => urlencode("user"),
"password" => urlencode("password"),
"messages" => urlencode("123456,123457,123458"),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<?
$url = "https://www.afilnet.com/api/basic/";
$fields = array(
"class" => urlencode("email"),
"method" => urlencode("getdeliverystatus"),
"messages" => urlencode("123456,123457,123458"),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERPWD, $user.":".$password);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 401)
{
// LOGIN ERROR
} else {
// SUCCESS LOGIN
}
?>
<?
# This example requires nusoap
require_once('nusoap.php');
$class="email";
$method="getdeliverystatus";
$user="user";
$password="password";
$messages="123456,123457,123458";
$output="";
# Create SOAP Client
$soapclient = new soapclient('https://www.afilnet.com/api/soap/index.php?wsdl');
# Call to method
$result = $soapclient->call($user, $password, $class, $method, '{"messages":"'.$messages.'","output":"'.$output.'"}');
?>
Parameter | Description | Compulsory / Optional |
---|---|---|
class=email | Class requested: Class to which the request is made | Compulsory |
method=getdeliverystatus | Class method requested: Method of the class to which the request is made | Compulsory |
user | User and e-mail of your Afilnet account | Compulsory |
password | Password of your Afilnet account | Compulsory |
messages | List of sending identifiers separated by , (commas) | Compulsory |
output | Output format of the result | Optional |
Answer:
- status
-
result (if status=success), here you will receive the following values:
- messageid
- sms
- deliverydate
- deliverystatus
- error (if status=error), here you will receive the error code
Error codes:
Code | Description |
---|---|
MISSING_USER | User or email not included |
MISSING_PASSWORD | Password not included |
MISSING_CLASS | Class not included |
MISSING_METHOD | Method not included |
MISSING_COMPULSORY_PARAM | Compulsory parameter not included |
INCORRECT_USER_PASSWORD | Incorrect user or password |
INCORRECT_CLASS | Incorrect class |
INCORRECT_METHOD | Incorrect method |
Which API for PHP should I use?
Discover the advantages and disadvantages of each of our APIs. Find out which API is best for your Software in PHP.
This API allows you to connect to us from PHP to send requests via HTTP GET requests. This request sends the parameters in the same URL as the request.
- HTTP GET is extremely simple to implement
- Information is sent unencrypted (passwords could be extracted from logs or cache)
- Maximum request of ~4000 characters
The POST request API allows you to connect to our API from PHP by sending request parameters via HTTP POST parameters. The information is sent independently of the URL.
- HTTP POST is simple to implement
- Information is sent encrypted
- There is no limit on the size of the request
- Medium security
The basic authentication API allows the use of GET and POST requests in PHP with an additional security layer, since in this case the username and password are sent in the header of the request.
- Basic authentication is easy to implement
- Access data is sent encrypted
- The size limit depends on the use of GET or POST
- Medium security
SOAP allows you to send requests in XML format with PHP, SOAP adds an extra layer of security to API requests.
- SOAP integration is more complex
- Information is sent encrypted
- There is no limit on the size of the request
- Medium / High security
Our JSON API allows you to send requests in JSON format with PHP, in addition this API adds the oAuth 2.0 protocol in the authentication that allows you to add an additional layer of security.
- JSON oAuth 2.0 integration is more complex
- Information is sent encrypted
- There is no limit on the size of the request
- High security
Connect PHP with our EMAIL API
Our Email API allows you to easily, quickly and efficiently. The process you need to follow to be able to use our API will only take a few minutes. Our company will offer you a free trial so that you can test the service.
Register as a client
In order to have access to the API you must be an Afilnet client. Registration will take a few minutes.
Request your free trial
Our company will offer you trial balance that will allow you to test with the API you need.
Integrate the API
Perform API integration using the programming language of your choice. If you have any questions or suggestions about the API, contact us
Welcome to Afilnet!
Everything ready!, has managed to improve its communications with Afilnet. We are here to support our API when you need it
Contact our team with any questions through the contact methods that we offer. Our team will try to offer you an immediate solution and will help you in the integration of our API in your Software.