Search the Community
Showing results for tags 'mail()'.
-
I am using magento for sending mail with condition, My code: <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $extra = $order->getIncrementId(); $message = " <tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = " <p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMail($finalMessage); } } public function sendMail($message) { $body ="$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('abc'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $emailTemplate->setToEmail('[email protected]'); $emailTemplate->send(); } } ?> Output : If order placed mail send to [email protected]. How to set email sender based on SKU $sku from order. I want : 1) If SKU starts with 2, email should go to the mail id [email protected], screenshot : 2) If SKU starts with 3, email should go to the mail id [email protected], screenshot : 3) If SKU starts with 4, email should go to the mail id [email protected], screenshot : FYI - If an order contains 10 items email should go separately based on SKU. But an order id the same must include all the emails.
-
Quite simple my mail is failing to send. The $_POST variable is not echo ing after being reassigned to $message and $email is not appearing either to satisfy the mail() function. I know i' <?php require_once __DIR__ . '/header.php'; require_once __DIR__ . '/includes/class_mtg_paginate.php'; $opts = ['grpgusers', 'gdemails']; $names = ['MS', 'GD']; $view = isset($_GET['view']) && in_array($_GET['view'], $opts) ? $_GET['view'] : 'grpgusers'; if (!$user_class->admin) $mtg->error("You don't have access"); if (array_key_exists('ms', $_POST)) { $db->query("SELECT id, email FROM grpgusers ORDER BY id ASC LIMIT 2"); $db->execute(); $rows = $db->fetch_row(); $success = 0; $failure = 0; echo 'Sending...<br />'; $message = stripslashes($_POST['message']); $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); foreach ($rows as $row) { $email = $row['email']; if (mail("$email", "A message from MS", "$message", "$headers")) ++$success; else ++$failure; } $mtg->success("Message sent to " . $mtg->format($success) . " user" . $mtg->s($success) . ". Failed to send to " . $mtg->format($failure) . " user" . $mtg->s($failure)); } if (array_key_exists('gd', $_POST)) { $db->query("SELECT id, email FROM gdemails ORDER BY id ASC LIMIT 2"); $db->execute(); $rows = $db->fetch_row(); $success = 0; $failure = 0; echo 'Sending...<br />'; $message = stripslashes($_POST['message']); foreach ($rows as $row) { $email = $row['email']; if (mail("$email", "A message from MS", "$message")) ++$success; else ++$failure; } $mtg->success("Message sent to " . $mtg->format($success) . " user" . $mtg->s($success) . ". Failed to send to " . $mtg->format($failure) . " user" . $mtg->s($failure)); } $pages = new Paginator(); if($_GET['view'] == "grpgusers") { $db->query("SELECT COUNT(id) FROM grpgusers"); $submit = "ms"; } else { $db->query("SELECT COUNT(id) FROM gdemails"); $submit = "gd"; } $db->execute(); $pages->items_total = $db->fetch_single(); $pages->mid_range = 5; $pages->paginate(); ?> <tr><th class='contenthead'>Mass Email</th></tr> <tr><td class='contentcontent'> <form action='staff_mail.php' method='post'> <table id='mttable' width='100%'> <tr> <th width='25%'>Message</th> <td width='75%'><textarea name='message' rows='10' cols='60'></textarea></td> </tr> <tr> <td colspan='2' class='center'><input type='submit' name='<?php echo $submit; ?>' value='Send Email' /></td> </tr> </table> </form> <br /> <div class='paginate'><?php echo $pages->display_pages(); ?></div> <br /> <form action="staff_mail.php" method="get"> <table width="100%" id='mttable'> <tr> <th width='25%'>Emailer List</th> <td width='75%'><select name='view' onchange='this.form.submit()'> <option value='grpgusers'>Select...</option> <?php $c = 0; foreach ($opts as $opt) { printf("<option value='%s'>%s</option>", $opt, $names[$c]); $c++; } ?></select></td> </tr> </table> </form> <br /> <table id='mttable' width='100%'> <tr> <td colspan='5' class='center'><?php if($_GET['view'] == "grpgusers") { echo "MS"; } else { echo "GD"; } ?> Emails</td> </tr> <tr> <th width='5%'>ID</th> <th width='35%'>Username</th> <th width='48%'>Email</th> <th width='12%'>Action</th> </tr><?php if($_GET['view'] == "grpgusers") { $db->query("SELECT id, username, email FROM grpgusers ORDER BY id ASC " . $pages->limit); } else { $db->query("SELECT * FROM gdemails ORDER BY emailid ASC " . $pages->limit); } $db->execute(); $rows = $db->fetch_row(); foreach ($rows as $row) { ?><tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['username']; ?></td> <td><?php echo $row['email']; ?></td> <td><?php echo '[Delete]'; ?></td> </tr><?php } ?></table> <br /> <div class='paginate'><?php echo $pages->display_pages(); ?></div> </td></tr><?php require_once __DIR__ . '/footer.php'; m missing something dumb so be gentle with me.
-
So, I use mail() to send form data to a client. Works great. Now I am trying to send email to the same client, but with an attachment. I know PHPmailer is preferred, but I'm old school and would like to get this to work. The file I want to send as attachment gets to the far end, but Outlook email displays the binary data instead of having the pdf as an attachment attachment and looks like this: Attached is the Legal Description for 24050240--8f082344de8525de682e9d6aa86aa83f Content-Type: application/pdf; name="Testfile1.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="Testfile1.pdf" JVBERi0xLjcNJcjIyMjIyMgNMSAwIG9iago8PC9OYW1lcyA4IDAgUi9PdXRsaW5lcyAyIDAgUi9U eXBlL0NhdGFsb2cvUGFnZXMgMyAwIFIvVmVyc2lvbi8xLjc+Pg0KZW5kb2JqCjIgMCBvYmoKPDwv VHlwZS9PdXRsaW5lcy9Db3VudCAwPj4NCmVuZG9iagozIDAgb2JqCjw8L0NvdW50IDEyL0tpZHNb OSAwIFIgNTAgMCBSIDc1IDAgUiA5OSAwIFIgMTI5IDAgUiAxNDUgMCBSIDE2OCAwIFJdL1R5cGUv UGFnZXM+Pg0KZW5kb2JqCjQgMCBvYmoKPDwvU3ViamVjdCgpL1Byb2R1Y2VyKEFzcG9zZS5QZGYg Zm9yIC5ORVQgOS4yLjEpL0NyZWF0aW9uRGF0ZShEOjIwMjQwMTI2MTE1NTQzKS9BdXRob3IoKS9N b2REYXRlKEQ6MjAyNDAxMjYxMTU1NDMpL0NyZWF0b3IoQXNwb3NlIEx0ZC4pL1RpdGxlKE11bHRp cGxlIERvY3VtZW50cyk+Pg0KZW5kb2JqCjggMCBvYmoKPDwvRGVzdHMgMTg0IDAgUj4+DQplbmRv ... ... more of this... The file size is 723709. Here is the code I am using: (I have some echo statements to help me trouble shoot.) Your help appreciated. function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { echo nl2br ("In funtion mail_attachment: filename = $filename\n"); $file = ($filename); echo nl2br ("In funtion mail_attachment: file = $filename\n"); echo nl2br ("In funtion mail_attachment: path = $path\n"); $file_size = filesize("$path/$file"); echo ("file_size = $file_size\n"); $handle = fopen($path.$filename, "rb"); echo ("handle = $handle"); //$content = file_get_contents($file); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); echo ("Content = $content\n"); $uid = md5(uniqid(time())); $eol = PHP_EOL; // Headers $header = "From: ".$from_name." <".$from_mail.">".$eol; $header .= "Reply-To: ".$replyto.$eol; $header .= "MIME-Version: 1.0".$eol; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\""; // // Message $header .= "--".$uid.$eol; $header .= "Content-type:text/plain; charset=iso-8859-1.".$eol; $header .= "Content-Transfer-Encoding: 8bit".$eol.$eol; //$message .= $body.$eol; $message .= "--".$uid.$eol; $message .= "Content-Type: application/pdf; name=\"".$filename."\"".$eol; // use different content types here $message .= "Content-Transfer-Encoding: base64".$eol; $message .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol; $message .= $content.$eol; $message .= "--".$uid."--"; if (mail($mailto, $subject, $message, $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!\n"; echo nl2br ("file = $file\n"); echo nl2br ("path.filename = $path.$filename\n"); } }