I see random spaces in the html mail which breaks entire html structure and gives the weird html mail.
I am using SENDY newsletter API to send mail to clients. The html mail is working fine in all other email clients like outlook express and so on.. except 'ZIMBRA' email client where I see random spaces which is leading to weird html mail.
For Ex: If image path is say http://www.example.com/12.jpg and it gives you
http://ww w.example.com/1 2.jpg
Code
$postdata = http_build_query(
array(
'api_key' => 'xxx',
'from_name' => 'xxx',
'from_email' => 'xxx',
'reply_to' => 'xxx',
'subject' => 'Daily',
'html_text' => html_content,
'list_ids' => 'hhjh',
'send_campaign' => 1
)
);
$opts = array('http' => array('method' => 'POST', 'header' => Array('Content: text/html', 'charset=UTF-8'), 'content' => $postdata));
Please help me, Thanks in advance.
Try using Trim function or try str_replace(' ','','the variable that generates the image')
I am finally able to find solution for this. I added encode property like this
$mail->encoding = base64. It worked.
Related
My aws/aws-sdk-php version is 2.7.27. The emails we sent are marked as spam. I found that my AWS account has got 8 dedicated IPs in Dedicated IPs page. But the sender IP of my email isn't any of the dedicated IPs, it's a shared IP of amazon SES. In developer document of SES, I found that they said I can make a Configuration Set to specify whick IP pool is used for sending. I add a param called 'ConfigurationSetName' as the doc said but it doesn't work, my emails are still sending through shared IPs. My code is like:
$sendingParams = array(
'Source' => $fromEmail,
'Destination' => array(
'ToAddresses' => is_array($email) ? $email : array($email),
//'CcAddresses' => is_array($ccEmail) ? $ccEmail : array($ccEmail),
//'BccAddresses' => is_array($bccEmail) ? $bccEmail : array($bccEmail),
),
'Message' => array(
// Subject is required
'Subject' => array(
// Data is required
'Data' => $subject,
'Charset' => 'utf-8',
),
// Body is required
'Body' => array(
'Html' => array(
// Data is required
'Data' => $content,
'Charset' => 'utf-8',
),
),
),
'ReplyToAddresses' => array($fromEmail),
'ReturnPath' => $returnPath,
'ConfigurationSetName' => 'system',
);
if (!empty($ccEmail)) {
$sendingParams['Destination']['CcAddresses'] = is_array($ccEmail) ? $ccEmail : array($ccEmail);
}
if (!empty($bccEmail)) {
$sendingParams['Destination']['BccAddresses'] = is_array($bccEmail) ? $bccEmail : array($bccEmail);
}
$result = $this->sdkClient->sendEmail($sendingParams);
What's the problem with my code? Should I change the version of the SDK?
I find the problem. My dedicated IPs are warming up, and I can't use them before they were totally warmed up.
I have tried to run the following code for sending multiple emails using mailgun API in PHP. But no email is sent using the code. My code is :
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mgClient = new Mailgun("my-api-key");
$domain = "sandboxfa3e9009746840be831c6edc9e9f1ee9.mailgun.org";
$result = $mgClient->sendMessage("$domain",
array('from' => 'Mailgun Sandbox - Test
<postmaster#sandboxfa3e9009746840be831c6edc9e9f1ee9.mailgun.org>',
'to' => 'email_1#gmail.com, email_2#gmail.com',
'subject' => 'Mailgun bulk-msg test for KB',
'text' => 'Your mail do not support HTML',
'html' => 'html-portion here...',
'recipient-variables' => '{"email_1#gmail.com": {"first":"Name-1",
"id":1}, "email_2#gmail.com": {"first":"Name-2", "id": 2}}')
);
var_dump($result);
?>
#===============================================
Have i do any mistake in the code to send multi email ? If you have any solution, please help.
I found this from their API. (Not as answer maybe. Just a reference)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mg = Mailgun::create('key-example');
# $mg->messages()->send($domain, $params);
$mg->messages()->send('example.com', [
'from' => 'bob#example.com',
'to' => 'sally#example.com',
'subject' => 'The PHP SDK is awesome!',
'text' => 'It is so simple to send a message.'
]);
Source
Aside from what Abdulla pointed out I see that you're writing "$domain" as the literal domain parameter. If you write it with quotation-marks, then it will be interpreted as a string, and not the variable itself.
Change the following and it should work:
$result = $mgClient->sendMessage("$domain",
[...]
to
$result = $mgClient->sendMessage($domain,
[...]
I am using Mailgun as my e-mail Service provider for sending E-mail to my Colleagues. I have created some attractive E-mail Templates. But, I don't know how to send it through Mailgun. Kindly guide me...
this is simple to do if you're using the PHP library from mailgun, available here: https://github.com/mailgun/mailgun-php
The below code will send an email to a colleague of yours, you can add as many to fields as you need!
Then simply edit the array 'html' :) and execute the script!
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0l');
$domain = "YOURDomain.mailgun.org";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'You#yourdomain.com',
'to' => 'your_colleague#someone.com',
'subject' => 'Hello',
'html' => 'some html code <b> goes here </b> and works <span style=\"color:red\">fine</span>'
));
Or you can do a file read of the template and store it temporarily:
$fileloc = fopen("/path/to/email_template.php", 'r');
$fileread = fread($fileloc, filesize("/path/to/email_template.php"));
# Instantiate the client.
$mg = new Mailgun('<your_api_key>');
$domain = "domain.com";
# Make the call to the client.
$mg->sendMessage($domain, array('from' => 'noreply#domain.com',
'to' => 'recipient#domain.com',
'subject' => 'Subject',
'html' => $fileread));
Try this
$content = view('email.info-request',
['sender_name' => Input::get('sender_name'),
'sender_email' => Input::get('senderr_email'),
'sender_subject' => Input::get('sender_subject'),
'sender_message' => Input::get('sender_message')])->render();
$mg->messages()->send('mydomain.com', [
'from' => Input::get('sender_email'),
'to' => 'admin#mydomain.com',
'subject' => 'Information Request',
'html' => $content]);
I am attempting to send mail using AWS SES sendEmail method, and I'm having trouble with an error. I have read this question: AWS SDK Guzzle error when trying to send a email with SES
I am dealing with a very similar issue. The original poster indicates that they have a solution, but did not post the solution.
My code:
$response = $this->sesClient->sendEmail('example#example.com',
array('ToAddresses' => array($to)),
array('Subject.Data' => array($subject), 'Body.Text.Data' => array($message)));
Guzzle code producing the error (from aws/Guzzle/Service/Client.php):
return $this->getCommand($method, isset($args[0]) ? $args[0] : array())->getResult();
Error produced:
Catchable fatal error: Argument 2 passed to Guzzle\Service\Client::getCommand() must be of the type array, string given
Looking at the Guzzle code, I can see that the call to getCommand will send a string if args[0] is set and is a string. If args[0] is NOT set then an empty array is sent.
What am I missing here please?
SOLUTION:
It turns out I was trying to use SDK1 data structures on the SDK2 code base. Thanks to Charlie Smith for helping me to understand what I was doing wrong.
For others (using AWS SDK for PHP 2) :
Create the client -
$this->sesClient = \Aws\Ses\SesClient::factory(array(
'key' =>AWS_ACCESS_KEY_ID,
'secret' => AWS_SECRET_KEY,
'region' => Region::US_EAST_1
));
Now, structure the email (don't forget that if you're using the sandbox you will need to verify any addresses you send to. This restriction doesn't apply if you have been granted production status) -
$from = "Example name <example#example.com>";
$to ="example#verified.domain.com";
$subject = "Testing AWS SES SendEmail()";
$response = $this->sesClient->getCommand('SendEmail', array(
'Source' => $from,
'Destination' => array(
'ToAddresses' => array($to)
),
'Message' => array(
'Subject' => array(
'Data' => $subject
),
'Body' => array(
'Text' => array(
'Data' => "Hello World!\n Testing AWS email sending."
),
'Html' => array(
'Data' => "<h1>Hello World!</h1><p>Testing AWS email sending</p>"
)
),
),
))->execute();
That should work now.
Here is the relevant section in the AWS SDK for PHP 2 documentation:
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Ses.SesClient.html#_sendEmail
I'm trying to use a PHP script to login to another web site (a Moodle install, in this case) by POSTING to the login page.
This code seems to partially work. The problem is that only the first parameter is recognized by the receiving end. For the code shown below, only the 'username' parameter is recognized. However, if you switch the order of 'username' and 'password' so that 'password' is listed first, then only 'password' is recognized using $_POST['password'].
$postdata = http_build_query(
array(
'username' => $currentUser,
'password' => $userPassword,
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($loginURL, false, $context);
Any idea on why only the first parameter is being recognized?
Ok, I see now that the code is correct and that something external is interfering with the POST request. This code was being run inside of Drupal so I think that has something to do with it. When I save this separately as a .php file it works as expected.