Mandrill ERROR: Connection could not be established with host smtp.mandrillapp.com - mandrill

I am not trying to do anything fancy. I am just trying to send an email using API of mandrill. I have included the library but I still get the error: "Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.mandrillapp.com [Connection refused #111]' in /home/laundryanna/public_html/mandrill/lib/classes/Swift/Transport/StreamBuffer.php:265 Stack trace: #0 /home/laundryanna/public_html/mandrill/lib/classes/Swift/Transport/StreamBuffer.php(62): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/laundryanna/public_html/mandrill/lib/classes/Swift/Transport/AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/laundryanna/public_html/mandrill/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /home/laundryanna/public_html/mandrill/mailed.php(26): Swift_Mailer->send(Object(Swift_Message), Array) #4 {main} thrown in /home/laundryanna/public_html/mandrill/lib/classes/Swift/Transport/StreamBuffer.php on line 265". Here is the code:
<?php
include_once "lib/swift_required.php";
$subject = 'Hello from Mandrill, PHP!';
$from = array('mail1#example.com' =>'EA CEO');
$to = array(
'email1#gmail.com' => '$_POST["e1"]',
'email1' => 'Recipient2 Name'
);
$text = "Mandrill speaks plaintext";
$html = "<em>Mandrill speaks <strong>HTML</strong></em>";
$transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
$transport->setUsername('***ore#gmail.com');
$transport->setPassword('******');
$swift = Swift_Mailer::newInstance($transport);
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
if ($recipients = $swift->send($message, $failures))
{
echo 'Message successfully sent!';
} else {
echo "There was an error:\n";
print_r($failures);
}
?>
Please tell me what to do... :(

Related

Trying to read "bounce list" from AWS SNS in PHP

I'm programming an application to send emails through Amazon SES.
I would like to read the bounces (hard/soft bounces) from Amazon SNS (SES and SNS are already linked).
I tried the code shared on StackOverflow, but i constantly get an error message
//Create a SESClient
$SnsClient = new Aws\Sns\SnsClient([
//'profile' => 'default',
'version' => '2010-03-31',
'region' => 'eu-west-1',
'credentials' => [
'key' => $DatabaseLink->aws_access_key_id,
'secret' => $DatabaseLink->aws_secret_access_key],
]);
try {
$_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'] = 'Notification';
// Retrieve the message
$message = Message::fromRawPostData();
// make validator instance
$validator = new MessageValidator();
// Validate the message
if ($validator->isValid($message)) {
if ($message['Type'] == 'SubscriptionConfirmation') {
// if it's subscription or unsubscribe event then call SubscribeURL
file_get_contents($message['SubscribeURL']);
} elseif ($message['Type'] === 'Notification') {
$subject = $message['Subject'];
$messageData = json_decode($message['Message']);
// use $subject and $messageData and take relevant action
}
}
} catch (Exception $e) {
// Handle exception
echo $e;
}
"Invalid POST data". I don't want to send a message for validation, i would like to get the list of email adresses that bounced. So, my backend can process them and remove them from my database.
Could you please help me to figure it out?
I'm going in circles with the aws documentation.

Twilio unable to record incoming call conversation (not related to leave a message)

In the incoming call back url
I have the next code:
Twilio Call id
if (isset($_REQUEST['CallSid'])){
$tw_call_id = $_REQUEST['CallSid'];
}
else {
$tw_call_id = '';<br />
}<br />
$sid = "Axxxx";
$token = "Txxxx";
$twilio = new Client($sid, $token);
$recording = $twilio->calls($tw_call_id)
->recordings
->create([
"recordingStatusCallback" => "https://mycode.php",
"recordingStatusCallbackEvent" => ["completed"],
"recordingChannels" => "dual"
]
);
After this I have a say() and a dial() , so I want to record the say and the dial , no only the dial call
I got the error
PHP Fatal error: Uncaught Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: Requested resource is not eligible for recording in /var/www/html/vendor/twilio/sdk/src/Twilio/Version.php
What I am looking for is to record the complete conversation from incoming call

Why is not my url a fully qualified url for paypal?

I have this code
<?php
require '..\..\vendor\autoload.php';
define('SITE_URL','https://www.historietas.mx');
$paypal = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'my_redential',
'my_secret'
)
);
?>
And this code
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(SITE_URL.'\controladores\pagos\pay.php?success=true')
->setCancelUrl(SITE_URL.'\controladores\pagos\pay.php?success=false');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
try{
$payment->create($paypal);
}
catch(PayPal\Exception\PayPalConnectionException $e){
echo $e->getCode();
echo $e->getData();
die($e);
}
echo $approvalUrl = $payment->getApprovalLink();
and I have this error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'ReturnUrl is not a fully qualified URL'
I don't know what's hapenning I am not using any special character in the url, why is giving me this error? please help, it is very frustating...
remove space from url from your Url that's the issue
include 'vendor/autoload.php';
$checkUrl = 'https://yourdomein.org/user/registration/paypaypal-ch?approval=true&plan=single&email=dghdg#dfgsdh.com&firstname=dshdh0d&lastname=dhdas';
try {
\PayPal\Validation\UrlValidator::validate($checkUrl);
echo "Validated\n";
} catch (InvalidArgumentException $ex) {
echo $ex->getMessage() . "\n";
}
Remove ?success=true
and
Remove ?success=false
from
$redirectUrls->setReturnUrl(SITE_URL.'\controladores\pagos\pay.php?success=true')
->setCancelUrl(SITE_URL.'\controladores\pagos\pay.php?success=false');
and it will wotk for sure.
I had the same problem and it was resolved by using
route('your route name '['parameter 1','parameter2'])
$redirectUrls->setReturnUrl(route('your route name '['parameter 1','parameter2']));

ZF2 read mail content

I need to read the content of a mail in a ZF2 project. I'm able to read the header and the contentType, but not the 'body'. The contentType = multipart/alternative. Until now I use thos following code:
$params = array('host' => 'myHost', 'user' => 'myUser', 'password' => 'myPwd');
$mail = new \Zend\Mail\Storage\Imap($params);
$cntMail = $mail->countMessages();
for ($i = $cntMail; $i > 0; $i--) { // reverse order
$message = $mail->getMessage($i);
if (stristr($message->subject, '[Ticket#: I' . 411401 . ']')) {
echo $message->subject . "\n";
echo $message->contentType;
if ($message->isMultipart())
echo 'is multipart';
// here the body
echo $mail->getRawContent($i); //throws an error
exit;
}
Any help will be appreciated, Andrea
I connected to smartermail and apparently it is not possible with ZF2 to get the content of mails in smartermail...

YouTube Analytics API + service access = Fatal error: Uncaught exception (500)

I am trying to get some YouTube Analytics reports using the API with a Service account in order to perform some CRON jobs. I've already solved the common problem of NTP server sync and, obviously, i've set up the API console properly.
<?php
ini_set('display_errors', 1);
require_once 'gapi/src/Google_Client.php';
require_once 'gapi/src/contrib/Google_YouTubeAnalyticsService.php';
// Define constants.
const CLIENT_ID = '************************.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = '************************#developer.gserviceaccount.com';
const KEY_FILE = '************************-privatekey.p12';
const MY_CHANNEL = '************************';
$client = new Google_Client();
$client->setApplicationName("YouTube Analytics API Test");
session_start();
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array("https://www.googleapis.com/auth/yt-analytics.readonly"),
$key)
);
$client->setClientId(CLIENT_ID);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$token = $client->getAccessToken();
$youtubeAnalyticsService = new Google_YouTubeAnalyticsService($client);
$optparam = array("dimensions" => "country", "max-results" => "10");
$reports = $youtubeAnalyticsService->reports->query("channel==" . MY_CHANNEL, "2013-09-01", "2013-09-25", "views", $optparam);
echo $reports;
?>
returns to me this message:
Fatal error: Uncaught exception 'Google_ServiceException' with message
'Error calling GET https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DmychannelID&start-date=2013-09-01&end-date=2013-09-25&metrics=views&dimensions=country&max-results=10: (500) Unknown error occurred on the server.' in /mydomain/gapi/src/io/Google_REST.php:66
Stack trace:
0 /mydomain/gapi/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest))
1 /mydomain/gapi/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest))
2 /mydomain/gapi/src/contrib/Google_YouTubeAnalyticsService.php(48): Google_ServiceResource->__call('query', Array)
3 /mydomain/myfile.php(45): Google_ReportsServiceResource->query('channel==...', '2013-09-01', '2013-09-25', 'views', Array)
4 {main} thrown in /mydomain/gapi/src/io/Google_REST.php on line 66
Any suggestion? Thank you all in advance!

Resources