Making my sender option to send attachment or not - php

Anybody have idea what happen with my sender? , trying to make an option to send attachment or not
if ($makassarid_setup['filesend'] == 1) {
$filepdf = file_get_contents($AddAttachment);
$mail->AddAttachment($filepdf);
}
Thats are from the MKSENDERS , the sender its self the $makassarid_setup came from the mks.setting.php as the config file, its have been included as the top of MKSENDERS file
as u see on if ($makassarid_setup['filesend'] == 1) {
it should be sending attachment if i have set 1 on the mks.setting.php file "filesend" => 1, (on mks.setting.php) , but it given me output when im execute the sender
PHP Notice: Undefined variable: AddAttachment in /home/ubuntu/workspace/DEATHhomo/MKSENDERS on line 125
PHP Warning: file_get_contents(): Filename cannot be empty in /home/ubuntu/workspace/DEATHhomo/MKSENDERS on line 125.
when im turn the "filesend" => 0, it send the email normally, without any error input, and the $filepdf is came from the mks.setting.php "filepdf" => "file/attachment/a.pdf", so it the filename not empty ofcourse, i would really appreciate any help from you.
Thanks Alot! :D

PHPMailer just needs the filename, not its contents, so it seems you want:
if($makassarid_setup['filesend']==1){
$mail->AddAttachment($filepdf);
}

if ($makassarid_setup['filesend'] == 1) {
$takeattachmentfromtheconfig = $makassarid_setup['filepdf']
$callingtheattachmentabove = file_get_contents($takeattachmentfromtheconfig);
$mail->AddAttachment($callingtheattachmentabove;
}
this is right?

Related

message: move The DestinationId parameter is missing

I want to move mails (copy or move), I use
Microsoft\Graph\Graph , guzzlehttp/guzzle and php
I am missing the DestinationId parameter
here is the query I am using
$graph->createCollectionRequest("POST","/users/xxx#xxxx.com/mailFolders/$inbox_id/childFolders/$folder_id/messages/$message_id/move/")->execute();
and I don't know where to put DestinationId.
here is the error code I got
{
"code":"ErrorInvalidParameter",
"message":"The value of the parameter 'DestinationId' is empty."
}
I found
$mailBody = array( "DestinationId" => "$message_id");
$graph->createCollectionRequest("POST","/users/xxx#xxxx.com/mailFolders/$inbox_id/childFolders/$folder_id/messages/$message_id/move/")->execute()
->attachBody($mailBody)
->execute();

PhpMailer, how do I write the variable value correctly for multiple addCC email address?

I have a PhpMailer working code as follow: (short version)
(the variable already defined before hand)
// Sender and recipient settings
$mail->setFrom($pengirim_email, $pengirim_nama);
$mail->addAddress($untuk_email, $untuk_nama);
$mail->addReplyTo($pengirim_email, $pengirim_nama);
Next, I add multiple email address for CC mail:
$mail-->addCC('aaa#gmail.com','Abdul');
$mail-->addCC('bbb#gmail.com','Borat');
It work as expected.
Now since I'm planning that the email address will come from the SQL query, so for the time being I want to know how do I have to fill the SQL 'CarbonCopy' column table with multiple email addresses - by trying to make a "hardcoded" variable value. So I try like this as the replacement for the addCC above:
$tembusan="'aaa#gmail.com','Abdul';'bbb#gmail.com','Borat'"; //not working
$CC = explode(';', $tembusan); //not working
for ($i = 0; $i < count($CC); $i++) {$mail->addCC($CC[$i]);} //not working
But it throw me an error like this :
Error in sending email. Mailer Error: Invalid address: (cc):
'aaa#gmail.com','Abdul'
So I change the $tembusan into like this:
$tembusan="aaa#gmail.com,Abdul;bbb#gmail.com,Borat"; //not working
It gives me almost the same like the error before:
Error in sending email. Mailer Error: Invalid address: (cc):
aaa#gmail.com,Abdul
Next, I try also this kind of code :
$tembusan="'aaa#gmail.com','Abdul';'bbb#gmail.com','Borat'"; //not working
$CC = explode(';', $tembusan); //not working
foreach($CC as $CCemail){$mail->AddCC($CCemail;} //not working
And it also throw the same error:
Error in sending email. Mailer Error: Invalid address: (cc):
'aaa#gmail.com','Abdul'
If I echo the last code like this foreach($CC as $CCemail){echo $CCemail. '<br/>';}, it give me a result like this :
'aaa#gmail.com','Abdul'
'bbb#gmail.com','Borat'
In my real code, I have a valid email address. The email address in the code above is just for an example.
Where did I do wrong ?
PS
btw, if I remove the "name" for the email address:
$tembusan="aaa#gmail.com;bbb#gmail.com"; //working
$CC = explode(';', $tembusan); //working
foreach($CC as $CCemail){$mail->AddCC($CCemail;} //working
it runs as expected (but in the gmail, the CC name is aaa and bbb).
Please do a further explode . try
$tembusan="aaa#gmail.com,Abdul;bbb#gmail.com,Borat";
$CC = explode(';', $tembusan);
for ($i = 0; $i < count($CC); $i++) {
$DD = explode(',', $CC[$i]);
$mail->addCC($DD[0], $DD[1]);
}
Please note that I have removed the ' characters . (you may use str_replace of PHP to eliminate these characters)

Prestashop Db::getInstance()->update() return Undefined variable

I tried to import my CSV file to update my products, it keeps give me time out and after 2 weeks, we ruled out the server is the problem ( we tried changing max_execution_time, memory_limit, or anything that we think would cause it)
The error logs showed following error:
PHP Notice: Undefined variable: return in /var/www/vhosts/22/xxxxxx/webspace/httpdocs/xxxxxx/controllers/admin/AdminImportController.php on line 1518
which is a customized code that we added to sort our products listing;
Following are the code
$prod_pos = get_object_vars($product);
if (isset($info['position']) && !empty($info['position']))
{
$update_prod_cat_id = array();
for ($i = 0; $i < count($product->category); $i++)
{
if (is_numeric($product->category[$i])){
$return &= Db::getInstance()->update('category_product', array(
'position' => $info['position'],
), '`id_category` = '.(int)$product->category[$i].' AND `id_product` = '.(int)$product->id);
}
else
{
$update_prod_cat_id[] = Category::searchByName($default_language_id, trim($product->category[$i]), true);
$return &= Db::getInstance()->update('category_product', array(
'position' => $info['position'],
), '`id_category` = '.(int)$pos_cat_id['id_category'].' AND `id_product` = '.(int)$product->id);
}
}
}
The funny thing is this code was working until we move the hosting to cloud hosting then every time we tried to upload a CSV file more than 300 lines, it will just timed out and the error log will show the above error!
I am wondering if the db_prefix needed for Db::getInstance()->update()
But I read it will automatically put it when we use this instance.
I am not sure. I tried everything I though it would work but it's not.
Any idea?
From what I see in the code, the varable $return is undefined on the two rows that is being assigned
May be the script really timeouts, but this can be confirmed during the debugging process. The code above seems OK.
The db prefix is automatically added in your case.

Sorting Imap mailbox by date using ImapMailbox.php

I have a customer support system which creates emails when an email is received. I used to postfix and a special configuration to get a hold of the emails to add extra features.
For example I want to include attachments that were sent from an email. The system doesnt do this , but creates an email with the subject , so I can include the attachments by matching the subjects.
I used ImapMailBox.php to read through the email contents.
It all works fine but I am getting an issue fetching the last email, so I am gettign contents from any other email with the same subject , so I need to fetch the latest email.
$mailboxP = new ImapMailbox('{127.0.0.1:143/novalidate-cert}',POSTFIX_EMAIL,POSTFIX_PASSWORD,ATTACHMENT_DIR, 'utf-8');
foreach($mailbox->searchMails('ALL') as $mailId)
$mail = $mailbox->getMail($mailId);
$mailx=(array)$mail;
$att=$mailx['attachments'];
I have tried using usort to the object $mail , with a function like this
function
mysort($a,$b) {
return strtotime($a->date)-strtotime($b->date);
}
and to the array with a function like this
function mysort($a,$b) {
return strtotime($a['date'])-strtotime($b['date']);
}
I have also tried using imap_sort to $mail and $mailx , but none of this works.
errors I am getting
imap_sort() expects parameter 1 to be resource, array given
imap_sort() expects parameter 1 to be resource, object given
usort() expects parameter 1 to be array, object given
when passing an array I get undefined index date but it defined ..
Can anyone please be kind enough to point me in the right direction.
You can add a function like this on ImapMailbox.php :
public function searchMailsSorted($imapCriteria = 'ALL') {
$this->checkConnection();
$mailsIds =imap_sort($this->mbox,SORTDATE,1,SE_UID,$imapCriteria,$this->serverEncoding);
return $mailsIds ? $mailsIds : array();
}
And then use it in your code like this:
foreach($mailbox->searchMailsSorted('ALL') as $mailId)
{
///insert code here
}
The easiest way is to use Php rsort() function.
<?php
$emailId = rsort($mailbox->searchMails('ALL');
?>

How to pass a 2 dimensional array value in a swift mailer setTo function

I am getting a 2 dimensional array value as a result after a for loop.The value is $chunk[$i][$j].And when I passed that value into setTo function,
the error showing as
Warning: preg_match() expects parameter 2 to be string, array given in H:\xampp
\htdocs\sngmarket\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Mime\Headers
\MailboxHeader.php line 350.
How do I solve this?.Here my code
$query = $em->createQuery("SELECT DISTINCT u.emailaddress FROM AcmeRegistrationBundle:userlist u");
$grp_emails[] = $query->getResult();
$chunk = array_chunk($grp_emails, 10);
$get_chunk_count = count($chunk);
for($i=0;$i<$get_chunk_count;$i++)
{
$count_inside_count = count($chunk[$i]);
for($j=0;$j<=$count_inside_count;$j++)
{
$mails=$chunk[$i][$j];
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('marketplace#socialnetgate.com')
->setTo($mails)
->setReturnPath('gowtham#ephronsystems.com')
->setBody('Hello World');
$this->get('mailer')->send($message);
return array();
}
}
I think you are overthinking this.
Have you looked at the documentation on how to send batch emails WITHOUT recipients being aware of each other? In your snippet each email contains up to 10 recipients, which may be better then sending all recipients, but still is pretty bad.
Have a look at Sending emails in batch and also at the plugins to make sure you don't reach the limit of emails you are allowed to send in a certain time frame.

Categories