uploaded file name in email subject - php

Below code will show file name in Email Body, but I want it to appear in Email Subject also.
Where I will put $files_list in subject ?
I tried
'subject' => __('$files_list uploaded for you','cftp_admin')
'subject' => __($files_list.'New files uploaded for you','cftp_admin'),
Not working. Here is the code :
$email_strings_file_by_user = array(
'subject' => __('New files uploaded for you','cftp_admin'),
'body' => __('The following files are now available for you to download.','cftp_admin'),
'body2' => __("If you prefer not to be notified about new files, please go to My Account and deactivate the notifications checkbox.",'cftp_admin'),
'body3' => __('You can access a list of all your files or upload your own','cftp_admin'),
'body4' => __('by logging in here','cftp_admin')
);
function email_new_files_for_client($files_list)
{
global $email_strings_file_by_user;
$this->email_body = $this->email_prepare_body('new_file_by_user');
$this->email_body = str_replace(
array('%SUBJECT%','%BODY1%','%FILES%','%BODY2%','%BODY3%','%BODY4%','%LINK%'),
array(
$email_strings_file_by_user['subject'],
$email_strings_file_by_user['body'],
$files_list,
$email_strings_file_by_user['body2'],
$email_strings_file_by_user['body3'],
$email_strings_file_by_user['body4'],
BASE_URI
),
$this->email_body
);
return array(
'subject' => $email_strings_file_by_user['subject'],
'body' => $this->email_body
);
}

your __(.....) function probably is used for language translations, so append the variable $files_list with translation, as change:
'subject' => __($files_list.'New files uploaded for you','cftp_admin'),
to
'subject' => $files_list . __('New files uploaded for you','cftp_admin'),

Related

How to use AWS SDK for PHP to send email by SES with dedicated IP?

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.

How to send E-mail Templates through Mailgun?

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]);

WAMP / Drupal 7 / SMTP module : Can't send mail with drupal_mail, but "testing mail" can send

I set up, with a Gmail account (smtp.gmail.com:465).
I'm using the SMTP module, and after setup, I can (i.e. have no problem with Gmail) send the "test e-mail" it offers in the admin page.
However, trying to call this function:
drupal_mail('casabaca_s3s', FORM_ALIAS_CONTACTO, 'luisfmasuelli#gmail.com', language_default(), array());
which is implemented here (hook impl.):
function casabaca_s3s_mail($key, &$message, $params)
{
$data = array();
foreach($params as $k => $v)
{
$data['${'.$k.'}'] = $v;
}
$messages = array(
FORM_ALIAS_CONTACTO => array(
'subject' => '',
'html.message' => <<<MESSAGE
MESSAGE
),
FORM_ALIAS_COTIZAR => array(
'subject' => '',
'html.message' => <<<MESSAGE
MESSAGE
),
FORM_ALIAS_TALLERES => array(
'subject' => '',
'html.message' => <<<MESSAGE
MESSAGE
),
FORM_ALIAS_EXONERADOS => array(
'subject' => '',
'html.message' => <<<MESSAGE
MESSAGE
),
FORM_ALIAS_AVALUO => array(
'subject' => '',
'html.message' => <<<MESSAGE
MESSAGE
),
FORM_ALIAS_MANTENIMIENTO => array(
'subject' => '',
'html.message' => <<<MESSAGE
MESSAGE
),
);
$base_message = $messages[$key];
$message['body']['plain'] = '<html><body>HTML version of "test message"</body></html>'; //drupal_wrap_mail(drupal_html_to_text(strtr($base_message['html.message'], $data)));
$message['body']['html'] = 'text version of "test messages"'; //drupal_wrap_mail(strtr($base_message['html.message'], $data));
$message['subject'] = 'test subject';//$base_message['subject'];
$headers = array(
'MIME-Version' => '1.0',
'Content-Type' => 'multipart/alternative; charset=UTF-8;',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal'
);
foreach ($headers as $key => $value) {
$message['headers'][$key] = $value;
}
}
doesn't work. The returned message comes as follows:
No se pudo enviar el correo electrónico. Contacte con la administración del sitio si persiste el problema.
(message in Spanish. possible English message could be - I don't know since I'm a total n00b and just using a Spanish Drupal 7 version -: E-mail couldn't be sent. Contact with site administration if the problem persists).
Q: What am I screwing?
Hypothesis: I think it's in my code, but I copied most of it and try to understand it
Goal: send a multiple alternatives email (please note, currently the options are just a stub, and not implemented), depending on six possibilities (each responding to a different form, a different feature, but currently they have dummy body and subject).
Preconditions: Drupal 7, PHP 5.4.16, SMTP module 7.x-1.0.
Edit: For those not being sure what the "test e-mail" is, see Here for a detailed example.
Found it ... had many problems.
The hook_mail implementation was in a file not yet included (required) in the .module, so it couldn't be found (and so, the message was empty, and that triggered the error).
Using ['plain'] and ['html'] as message elements did not create the multipart/alternative. Had to create it explicitly (i.e. boundaries).
There was something with the cache, because mail() was not bypassed (it was with the testing email but not with the actual email).
(summary: a 8th-layer error).
In some cases problem might be in the mail_system variable. It should be set to SmtpMailSystem.
Some modules like Mail System or Mime Mail change it.
See also drupal_mail_system and drupal_mail.

print screen > ckeditor > CakePHP CakeEmail

I have a CKEditor 3.6.5 (revision 7647) field (on a CakePHP 2.2.1 site) where users paste print screen images (only works on Firefox). The html generated by the paste (button paste from word) is something like this:
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==" />
At a certain point I have to send by Email the html on these fields which should include the images.
Reading [base64-encoded-images-in-email-signatures][1] and [how-to-embed-images-in-email][2] I figured that the Email should have an attachment with the image.
My question is how can I transform the src of the image on a file? This way I intend to transform the HTML before send.
I have tried with success to attach a file with:
$data = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==');//file_get_contents('http://' . env('HTTP_HOST') . $fileInfo['url'] . '/disable-auth-key:' . Configure::read('Security.salt') . '.' . $fileInfo['ext']);
$handle = fopen(TMP . 'print_screen.png', 'w+');
fwrite($handle, $data);
fclose($handle);
$email = new CakeEmail(array(
'log' => true,
'config' => 'smtp',
'returnPath' => 'return#mydomain.pt',
'from' => array('app#mydomain.pt' => 'APP'),
'to' => array('name#domain.pt' => 'Name'),
'emailFormat' => 'html',
'subject' => 'image test',
'domain' => '#uab.pt',
'attachments' => array(
'print_screen.png' => array(
'file' => TMP . 'print_screen.png',
'mimetype' => 'image/png',
'contentId' => 'Print-Screen-01'
)
)
));
$email->send('test|<img src="cid:print_screen.png#Print-Screen-01">|');
On GMail I have access to the attachment file but on the body no image. Where is the source
<div id=":85x">test|<img>|</div>
On Outlook, no attachments and the source is
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">test|<img src="cid:print_screen.png#Print-Screen-01">
I'm also open to other solutions that achieve the same result.
on the src attribute of the image tag the cid value should be I was using #.
The correct line of code
$email->send('test|<img src="cid:Print-Screen-01">|');

Facebook PHP image

I've serached a little but I didn't find anything that could solve my problem.
I've managed to post on page as page admin, link is added correctly, but image isn't attached. My code:
Blahblah authentication, etc.
$attachment = array(
'message' => 'text',
'name' => 'Name',
'link' => 'http://somelink.com',
'description' => '',
'access_token' => $ACCESS_TOKEN
);
if(something) $attachment['media'] = array(array('type'=>'image', 'src'=>'http://'.$_SERVER['HTTP_HOST']."/media/file/image_by_id/".$data['thumb_file_tree_id'].'/?w=400&h=500', 'href'=>'http://somelink.com'));
try {
if($facebook->api('/XXX/feed', 'post', $attachment))
{
echo 'Hooray, ok';
}
} catch (FacebookApiException $e) {
echo 'Damn';
}
Result: Correctly posted news with link ('Hooray, ok'), but without image. Can it be due to PHP generated image, and not png/jpg/gif extension? I've added some additional headers like etag, accepted-ranges, last modified, etc. What am I doing wrong (again)?
'Something' is true, checked with print_r whole attachment array.
E: Again removed [0]
To just attach an image, you can use the picture key in your attachment.
$attachment = array(
'message' => 'text',
'name' => 'Name',
'link' => 'http://somelink.com',
'description' => '',
'access_token' => $ACCESS_TOKEN,
'picture' => 'http://example.com/example.jpg'
);

Categories