class.directmail.php
928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
if (!class_exists('DMSubscribe'))
{
class DMSubscribe
{
public function submitSubscribeForm( $form_id, $email, &$error_msg) {
$post_data['subscriber_email'] = $email;
$post_data['form_id'] = $form_id;
$ch = curl_init( 'http://dm-mailinglist.com/subscribe?format=json' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data );
$result = curl_exec($ch);
if ( $result === false ) {
$error_msg = sprintf( "Connection failed: (%d) %s", curl_errno( $ch ), curl_error( $ch ) );
}
else if ( curl_getinfo( $ch, CURLINFO_HTTP_CODE ) != 200 ) {
$json = json_decode( $result, true );
if ( $json === null ) {
$error_msg = "Unable to decode response: $result";
}
else {
$error_msg = $json['Message'];
}
}
else {
$success = true;
}
curl_close( $ch );
return $success;
}
}
}
?>