I'm new in Amazon SES and I'm trying to send an email with this code:
<?php
require_once 'aws/sdk.class.php';
$ses = new AmazonSES();
$to = array('ToAddress' => 'mario#wowfi.com');
$content = array('Subject.Data' => 'Tema', 'Body.Text.Data' => 'hello');
$r = $ses->send_email("mario#wowfi.com", $to , $content);
print_r($r);
?>
In the output it says: Missing required header 'To', what am I doing wrong?
I already solved it, I had two problems in my code:
The index "ToAddress" is incorrect, it has to be in plural "ToAddresses".
And the value it has to be an array like this: array('mario#wowfi.com')
Related
I have tried to fix this issue but unable to do so. Field 'card_nonce' is not found on the server although it is recently created. I have used npm and node to generate a card_nonce.
Code Used:
$billing_address = new Address();
$billing_address->setAddressLine1('500 Electric Ave');
$billing_address->setAddressLine2('Suite 600');
$billing_address->setLocality('New York');
$billing_address->setAdministrativeDistrictLevel1('NY');
$billing_address->setPostalCode('10003');
$billing_address->setCountry('AU');
// $body = new CreateCustomerCardRequest($_POST['nonce']);
$body = new CreateCustomerCardRequest('CBASECw9ri-7s1THlCWDoSVsVY8');
$body->setBillingAddress($billing_address);
$body->setCardholderName('Gaurav Gulati');
$api_response = $customersApi->createCustomerCard($customer_id, $body);
if ($api_response->isSuccess()) {
$result = $api_response->getResult();
$customer_card = $api_response->getCard();
$customer_card_id = $customer_card->getId();
} else {
$errors = $api_response->getErrors();
}
Response:
[0] => Square\Models\Error Object
(
[category:Square\Models\Error:private] => INVALID_REQUEST_ERROR
[code:Square\Models\Error:private] => NOT_FOUND
[detail:Square\Models\Error:private] => Resource not found.
[field:Square\Models\Error:private] => card_nonce
)
Anyone has idea how to resolve this error.
You've removed the "cnon:" from the parameter. "CBASECw9ri-7s1THlCWDoSVsVY8" should be cnon:CBASECw9ri-7s1THlCWDoSVsVY8.
I have integrated sendgrid in Laravel and I managed to send the email template of sendgrid in emails but I am not able to replace the content in the email templates. I am using Sendgrid Web API V3.
I followed the steps given in the below link but it is not replacing the variables in template with my dynamic data.
Link: How to pass dynamic data to email template desgined on sendgrid webapp ? :-| Sendgrid
Here is code
$sg = new \SendGrid('API_KEY');
$request_body = json_decode('{
"personalizations":[
{
"to":[
{
"email":"example#example.com"
}
],
"subject":"Hello World from the SendGrid PHP Library!"
}
],
"from":{
"email":"from#example.com"
},
"content":[
{
"type":"text/html",
"value":"<html><body> -name- </body></html>"
}
],
"sub": {
"-name-": ["Alice"]
},
"template_id":"xxxxxx-xxx-xxxxxxxx"
}');
$mailresponse = $sg->client->mail()->send()->post($request_body);
echo $mailresponse->statusCode();
echo $mailresponse->body();
echo $mailresponse->headers();
Please help.
This works perfectly and is much simpler than the solutions already posted:
$email = new \SendGrid\Mail\Mail();
$email->setFrom( "from#example.com", "Some guy" );
$email->addTo( "to#example.com", "Another guy" );
$email->setTemplateId(
new \SendGrid\Mail\TemplateId( TEMPLATE_ID )
);
// === Here comes the dynamic template data! ===
$email->addDynamicTemplateDatas( [
'variable1' => 'Some stuff',
'templatesRock' => 'They sure do!'
] );
$sendgrid = new \SendGrid( API_KEY );
$response = $sendgrid->send( $email );
I have overcome this issue by using another way. Below is code that is working fine. May be help some one..
//create mail object
$mail = new \SendGrid\Mail();
//set from
$from = new \SendGrid\Email("SENDER NAME", "SENDER EMAIL");
$mail->setFrom($from);
//set personalization
$personalization = new \SendGrid\Personalization();
$to = new \SendGrid\Email("RECEIVER NAME", "RECEIVER EMAIL");
$personalization->addTo($to);
$personalization->setSubject("SUBJECT");
//add substitutions (Dynamic value to be change in template)
$personalization->addSubstitution(':name', "Any");
$mail->addPersonalization($personalization);
$mail->setTemplateId("TEMPLATE_ID");
//send email
$sg = new \SendGrid("API_KEY");
$response = $sg->client->mail()->send()->post($mail);
It's a little bit late but maybe this can help some one to. I faced the same problem and #bwest answer helped me to solve it:
The substitutions values cannot be an array and the should look like:
`"personalizations":[{
"to":[{
"email":"example#example.com"
}],
"subject":"Hello World from the SendGrid PHP Library!",
"substitutions": {
"-name-": "Alice"
}
}
],
...
IN JAVA use:
Personalization personalization = new Personalization();
and its methods for sending the dynamic data to sendgrid template and use {{}}
for receiving the data on sendgrid.
Mail_Mime 1.8.9
Mail 1.2.0
php 5.4.12
project = run from my localhost dev computer (LAN).
Hello, I am attempting to add an image to my email I am sending out using MailMime. The image never loads. I'll go through the steps below:
Here I am stripping everything off of the image but the image name and extension (ie:noimage.jpg). I then create a link for non image related purposes, I then create the image tag using the stripped image name and extension.
$url = substr($baseImage, 36);
$domainName = DomainNameUtil::getWebSiteDomainName();
$projectPath = DomainNameUtil::getPathToProject();
$productUrl = $domainName . $projectPath . "/client/app/#/products/" . $product->id;
$productLink = "<a href='$productUrl'>$product->name</a>";
$string = "<img src='$url' /><br />";
Here I am sending the message
$mailConfig = MailConfigurationUtil::getMailConfigurationData();
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$crlf = "\n";
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setHTMLBody($body);
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', array (
'host' => $mailConfig->mailServer,
'port' => $mailConfig->port,
'auth' => true,
'username' => $mailConfig->userName,
'password' => $mailConfig->password
));
$productManager = new ProductManager();
$ordersManager = new OrdersManager();
$orderVirtualItem = $ordersManager->getOrderVirtualItemByBoxId($boxId);
$product = $productManager->getProductById($orderVirtualItem->itemId);
$url = $product->baseImage;
$domain = DomainNameUtil::getWebSiteDomainName();
$path = DomainNameUtil::getPathToProject();
$r = substr($url, 5);
$finalUrl = $domain . $path . $r;
$mime->addHTMLImage(file_get_contents($finalUrl),'image/jpeg',basename("noimage"),false, "blackstone");
$body = $mime->get();
$mail = $smtp->send($to, $headers, $body);
In the example above, I know the image is called noimage.jpeg, so in the addHtmlImage above I simply stated the name. I am under the impression that the name used in addHtmlImage has to be the same name as the image name in the image src tag in the html body.
When I actually send my email I get the email and I get some text saying there is an image, but the image tag in my email body does not load.
Also, looking at it under firebug it has a proxy attached to the image src. Also it references it as PROXYADDRESS#http://noimage.jpg
Anyone have experience in this that can help me understand why the image is not loading?
For reference, I saw someone posting this method online and tried copying them. before this I had even tried putting the whole url in the image src and not adding the image to MIME, and it did not work.
i got pretty similar problem here.
What i got so far: it depends on phpversion (and installed Mail_Mime).
Mail_Mime seems to be "broken" under php 5.4.30
If i run my script under php 5.2.17 all images show up correctly
If i run my script under php 5.4.30 all images do not show up correctly
when i compare both sourcecodes, it seems, Mail_Mime under 5.4.30 gets messy with the order of boundarys and the Content-Type:
Content-Type: multipart/alternative; in 5.2.17
Content-Type: multipart/related; in 5.4.30enter image description here
When specifying a context-id (the last parameter to addHtmlImage()) you must reference the image in the html message correctly: <img src="cid:context-id#local" />. Of course replacing context id with your own context id for each image to show.
here is the problem, couldn't find much googling, hope somebody here got the answer for this.
My PHP file is sending emails as feedback to me, and it takes 5 arguments,
whenever I send long arguments to my PHP file, it trims the end of argument 5, which is the longest one, how can I fix that?
To be more clear argument 5 is pretty much the email body.
Here is the PHP code:
<?php
include('Mail.php');
$arg1 = $argv[1]; //appName and version
$arg2 = $argv[2]; //ErrorMessage
$arg3 = $argv[3]; //ErrorData
$arg4 = $argv[4]; //ErrorSource
$arg5 = $argv[5]; //ErrorStackTrace
$arg1 = $_GET['arg1'];
$arg2 = $_GET['arg2'];
$arg3 = $_GET['arg3'];
$arg4 = $_GET['arg4'];
$arg5 = $_GET['arg5'];
$subject = $arg1 ;
$errorMessage = $arg2;
$ErrorData = $arg3;
$ErrorSource = $arg4;
$ErrorStackTrace = $arg5;
$recipients = "myemail";
$from = "errorreport#user.com" ;
$headers = array (
'From' => $from,
'To' => $recipients,
'Subject' => $subject,
);
$body = "ErrorMessage: "."\n".$errorMessage."\n"."ErrorData: "."\n".$ErrorData."\n"."ErrorSource: "."\n".$ErrorSource."\n"."ErrorStackTrace: "."\n".$ErrorStackTrace;
$mail_object =& Mail::factory('smtp',
array(
'host' => 'prwebmail',
'auth' => true,
'username' => 'user',
'password' => 'pass', ));
$mail_object->send($recipients, $headers, $body);
?>
I can see your code is referencing $_GET variables, please change your form to use a method of POST
If you are able to, shy away from GET method forms when sending large data.
find:
<form method="get">
replace with:
<form method="post">
then change:
$arg1 = $_GET['arg1'];
to:
$arg1 = $_POST['arg1'];
etc...
I cant figure this out so I'm hoping you can lend a hand.
I am creating a twilio app, and I'm including this entire file in a foreach loop. But it keeps breaking my loop and wont continue after it runs.
It works great, but the foreach this is included inside of will not continue after it runs.
Any ideas?
Thanks,
Nick
<?php
//shorten the URL
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$ebay_url);
// Include the PHP TwilioRest library
require "twilio/twilio.php";
// Twilio REST API version
$ApiVersion = "2010-04-01";
// Set our AccountSid and AuthToken
$AccountSid = "removed";
$AuthToken = "removed";
// Instantiate a new Twilio Rest Client
$client = new TwilioRestClient($AccountSid, $AuthToken);
// make an associative array of server admins
$people = array(
"removed"=>"Nick",
//"4158675310"=>"Helen",
//"4158675311"=>"Virgil",
);
// Iterate over all our server admins
foreach ($people as $number => $name) {
// Send a new outgoinging SMS by POST'ing to the SMS resource */
// YYY-YYY-YYYY must be a Twilio validated phone number
$response = $client->request("/$ApiVersion/Accounts/$AccountSid/SMS/Messages",
"POST", array(
"To" => $number,
"From" => 'removed',
"Body" => 'Alert! '.$title.' found for '. $price. '. View the item here: '.$tinyurl,
));
if($response->IsError)
echo "Error: {$response->ErrorMessage}\n";
else
echo "Sent message to: {$response->ResponseXml->SMSMessage->To}\n";
}
?>
I think the problem is that you're doing a require inside the for loop. There are objects defined in that twilio library so the second time you require it, the classes get defined again and this throws an error.
If you have error_reporting(E_ALL) set then you'll see an exception to that effect in your output.
I would either change it to a require_once or move it out of the for loop.
I hope that helps.