Angularjs POST to PHP printing blank values in email and console - php

I'm trying to submit values from angularjs to a php page, then have the php page send the values to an email. The problem is that the variables sent to the email are printing blank. When in my IDE, the variables will dump to the log properly, but when the same action is performed on a site on the internet (tried on two separate websites), the variables intended to be printed into the email do not print to the log on a dump.
https://github.com/Cameron64/BCIS4610
PHP code:
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && strpos($_SERVER['CONTENT_TYPE'], 'application/json') === 0 ) {
$postdata = file_get_contents('php://input');
$_POST = json_decode($postdata, true);
$_REQUEST = array_merge($_REQUEST, $_POST);
}
//$data['message'] = $_POST['customer'];
$data = json_decode($_POST['customer']);
//var_dump($data);
$basket = array();
$basketQuantities = array();
$email = $data->email;
$phone = $data->num;
$company = $data->restaurant;
$products = $data->product;
$quantities = $data->quantities;
$comments = $data->comments;
$counter = 0;
//var_dump($_POST['customer']);
for($i=0; $i<= sizeof($products,0)-1; $i++){
array_push($basket, $data->product[$i]->id);
}
for($i=0; $i<= sizeof($products,0)-1; $i++){
if($data->quantities[$i] != null)
{$basketQuantities[$i]=$data->quantities[$i];
}
else{
array_push($basketQuantities[$i], "1");
};
}
$final = "";
$final .= "Email: " . $email . "\n"
. "Company Name: ". $company . "\n"
. "Phone Number: ". $phone . "\n".
"They ordered: \n";
for($i=0; $i <= sizeof($products,0)-1; $i++){
$final .= $basket[$i] . "\t" . $basketQuantities[$i] . "\n";
}
if($comments != null){
$final .= "They also left a comment with their order:" . "\n" . wordwrap($comments);
}
$mailTo = "myemail#ymail.com";
$mailSubject = "New Order";
var_dump($final);
if($counter < 1){
mail($mailTo,$mailSubject,$final);
$counter++;
}
AngularJS code
this.basket =[];
this.customer ={};
this.customer.email = "";
this.customer.num = "";
this.customer.restaurant = "";
this.customer.product=[];
this.customer.quantities=[];
this.customer.comments= "";
this.formSubmit = function(){
if(document.getElementById('email').checkValidity() && document.getElementById('tel').checkValidity()
&& document.getElementById('name').checkValidity()){
lol = this;
$http({
method: 'POST',
url: 'php/SendOrder.php',
data: $.param({'customer' : JSON.stringify(lol.customer)}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).
success(function(response) {
console.log(response);
window.location = "invoice.html";
})
}
};
The values are populated via an nd-model in for form. I don't believe it is being submitted as a form, don't know if that changes anything.

Related

post data like this value[0]value hot to get it in php?

I am using Ajax and this is my post data:
auto[0].aantal:1
auto[0].berijder:erwrw
auto[0].klant:ertert
auto[0].ordernummer:345345
auto[1].aantal:1
auto[1].berijder:werwer
auto[1].klant:ertert
auto[1].ordernummer:345345
auto[2].aantal:1
auto[2].berijder:werwer
auto[2].klant:ertert
auto[2].ordernummer:345345
and in PHP I am doing the following
$array = $_POST['auto'];
for ($i = 0; $i < count($array); $i++) {
$key=key($array);
$val=$array[$key];
if ($val<> ' ') {
$message_body .= "<p>" . $key ." = ". $val ." <p><br> ";
}
next($array);
}
but that is not giving me all the data, what am I doing wrong? and what can I do to get all the data? thanks for the help so far!!

How to use templates or dynamic content for php email sending

PHPMailer is a good option to send email, and mail() function too, but the thing is that generating dynamic content for the email body, and subject are not the best.
for example I've created a php file with the body templates or a class with the same, but are so difficult to maintain.
What do you recomend for organizing that code?
Is there a Way to create email templates? (like twig).
How do you organize folders and files?
Is there any doc recommendation for that?
thanks for your help
It's no different than what you're already doing in PHP to generate dynamic HTML. Except that instead of sending the generated HTML output via your web server to a client UA, you're sending it to an email UA via an MTA.
20 years ago someone thought to invent a good templating engine to generate dynamic content (it was called PHP). It turns out it's still incredibly useful today.
Let's say you have a template file that looks like this for your email.
<table>
<?php foreach($rows as $row) { ?>
<tr>
<?php foreach($row as $column) { ?>
<td><?=$column?></td>
<?php } ?>
</tr>
<?php } ?>
</table>
Let's say have some templating system that renders these templates with perhaps something like this.
class Template {
protected $templateFile = "";
protected $templateVars = [];
public function __construct($templateFile, Array $templateVars= []) {
$this->templateVars = $templateVars;
$this->templateFile = $templateFile;
}
public function __toString() {
export($this->templateVars, EXTR_SKIP);
ob_start();
include $this->templateFile;
return ob_get_clean();
}
}
Now, you could expand upon this very simple abstraction of templating a bit further to include things like your email subject line, sender email address, etc...
class SendEmail {
public function __construct($to, $subject, $template, Array $data) {
$template = new Template($file, $data); // create the email template
$this->emailBody = (string) $template; // generate the content
$this->to = $to;
$this->subject = $subject;
}
public function send() {
// Send email using PHP mailer or whatever here
}
}
$tempalteContent = mysqli_query($conn, "select * from newsletter_template where name like '%$template%'");
if (mysqli_num_rows($tempalteContent) > 0) {
$validate = 0;
$messageFinal = '';
$message = '';
$row = mysqli_fetch_array($tempalteContent);
$template_id = $row['id'];
$productInc = $row['productsInc'];
$blogInc = $row['blogInc'];
$templateMsg = htmlspecialchars_decode($row['description']);
$divData = '';
$blogData = '';
if ($blogInc == 1 && $productInc == 1) {
/* * Product Query* */
$productQuery = mysqli_query($conn, "select * from newsletter_products where newsletter_tempalte_id = $template_id");
if (mysqli_num_rows($productQuery) > 0) {
$width = '';
$website = "http://demo.com/";
if (mysqli_num_rows($productQuery) > 2) {
$width = '100%';
} else if (mysqli_num_rows($productQuery) > 1) {
$width = '100%';
}
for ($i = 0; $i <= mysqli_num_rows($productQuery); $i++) {
$row[$i] = mysqli_fetch_array($productQuery);
$product_id[$i] = $row[$i]['product_id'];
$productDetails[$i] = mysqli_query($conn, "select * from products where product_id = $product_id[$i]");
if (mysqli_num_rows($productDetails[$i]) > 0) {
$rowproduct[$i] = mysqli_fetch_array($productDetails[$i]);
$productName[$i] = $rowproduct[$i]['product_name'];
$productImg[$i] = $website . $rowproduct[$i]['product_img'];
$productDesp[$i] = htmlspecialchars_decode($rowproduct[$i]['product_desp']);
$divData .= "<div style='width:" . $width . ";float:left;padding:7px;text-align:justify'><span style='width:100%;padding-bottom:5px;float:left'><img src='" . $productImg[$i] . "' width='30%' height='30%' style='max-width:100px;max-height:100px'></span><b style='vertical-align:bottom'>" . $productName[$i] . "</b><span style='font-size:12px;'>" . $productDesp[$i] . "</span></div>";
}
$validate++;
}
}
/* * Blog Query* */
$blogQuery = mysqli_query($conn, "select * from newsletter_blogs where newsletter_template_id = $template_id");
if (mysqli_num_rows($blogQuery) > 0) {
$width = '';
$website = "http://demo.com/";
if (mysqli_num_rows($blogQuery) > 2) {
$width = '100%';
} else if (mysqli_num_rows($blogQuery) > 1) {
$width = '100%';
}
for ($i = 0; $i <= mysqli_num_rows($blogQuery); $i++) {
$row[$i] = mysqli_fetch_array($blogQuery);
$blog_id[$i] = $row[$i]['blog_id'];
$blogDetails[$i] = mysqli_query($conn, "select * from blog where id = $blog_id[$i]");
if (mysqli_num_rows($blogDetails[$i]) > 0) {
$rowblog[$i] = mysqli_fetch_array($blogDetails[$i]);
$blogName[$i] = $rowblog[$i]['title'];
$blogImg[$i] = $website . $rowblog[$i]['img'];
$blogDesp[$i] = htmlspecialchars_decode($rowblog[$i]['desp']);
$blogData .= "<div style='width:100%;float:left;padding:7px;text-align:justify'><span style='width:100%;padding-bottom:5px;float:left'><img src='" . $blogImg[$i] . "' width='30%' height='30%' style='max-width:100px;max-height:100px'></span><b style='vertical-align:bottom'>" . $blogName[$i] . "</b><span style='font-size:12px;'>" . $blogDesp[$i] . "</span></div>";
}
$validate++;
}
}
$message = $templateMsg . $divData . $blogData;
} else if ($productInc == 1 && $blogInc == 0) {
$productQuery = mysqli_query($conn, "select * from newsletter_products where newsletter_tempalte_id = $template_id");
if (mysqli_num_rows($productQuery) > 0) {
$width = '';
$website = "http://demo.com/";
if (mysqli_num_rows($productQuery) > 2) {
$width = '100%';
} else if (mysqli_num_rows($productQuery) > 1) {
$width = '100%';
}
for ($i = 0; $i <= mysqli_num_rows($productQuery); $i++) {
$row[$i] = mysqli_fetch_array($productQuery);
$product_id[$i] = $row[$i]['product_id'];
$productDetails[$i] = mysqli_query($conn, "select * from products where product_id = $product_id[$i]");
if (mysqli_num_rows($productDetails[$i]) > 0) {
$rowproduct[$i] = mysqli_fetch_array($productDetails[$i]);
$productName[$i] = $rowproduct[$i]['product_name'];
$productImg[$i] = $website . $rowproduct[$i]['product_img'];
$productDesp[$i] = htmlspecialchars_decode($rowproduct[$i]['product_desp']);
$divData .= "<div style='width:" . $width . ";float:left;padding:7px;text-align:justify'><span style='width:100%;padding-bottom:5px;float:left'><img src='" . $productImg[$i] . "' width='30%' height='30%' style='max-width:100px;max-height:100px'></span><b style='vertical-align:bottom'>" . $productName[$i] . "</b><span style='font-size:12px;'>" . $productDesp[$i] . "</span></div>";
}
$validate++;
}
}
$message = $templateMsg . $divData;
} else if ($blogInc == 1 && $productInc == 0) {
$blogQuery = mysqli_query($conn, "select * from newsletter_blogs where newsletter_tempalte_id = $template_id");
if (mysqli_num_rows($blogQuery) > 0) {
$width = '';
$website = "http://demo.com/";
if (mysqli_num_rows($blogQuery) > 2) {
$width = '100%';
} else if (mysqli_num_rows($blogQuery) > 1) {
$width = '100%';
}
for ($i = 0; $i <= mysqli_num_rows($blogQuery); $i++) {
$row[$i] = mysqli_fetch_array($blogQuery);
$blog_id[$i] = $row[$i]['blog_id'];
$blogDetails[$i] = mysqli_query($conn, "select * from blog where id = $blog_id[$i]");
if (mysqli_num_rows($blogDetails[$i]) > 0) {
$rowblog[$i] = mysqli_fetch_array($blogDetails[$i]);
$blogName[$i] = $rowblog[$i]['title'];
$blogImg[$i] = $website . $rowblog[$i]['img'];
$blogDesp[$i] = htmlspecialchars_decode($rowblog[$i]['desp']);
$blogData .= "<div style='width:100%;float:left;padding:7px;text-align:justify'><span style='width:100%;padding-bottom:5px;float:left'><img src='" . $blogImg[$i] . "' width='30%' height='30%' style='max-width:100px;max-height:100px'></span><b style='vertical-align:bottom'>" . $blogName[$i] . "</b><span style='font-size:12px;'>" . $blogDesp[$i] . "</span></div>";
}
$validate++;
}
}
$message = $templateMsg . $blogData;
} else {
$message = $templateMsg;
}
$messageFinal = '<div style="width:100%">' . $message . '</div>';
echo $validate;
} else {
echo "Fail";
exit();
}
$subscribers = explode(',', $_POST['subscribers']);
for ($i = 0; $i < count($subscribers); $i++) {
$to = $subscribers[$i];
$subject = $template;
$from = 'demo#demo.com';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: Demo' . "\r\n" .
'Reply-To: Your Email Id' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<!DOCTYPE html><html><body>';
$message .= $messageFinal . $footer;
$message .= '</body></html>';
// Sending email
if (mail($to, $subject, $message, $headers)) {
$validate++;
} else {
$validate = 0;
}
}

php array values not being pushed onto associative array

I wrote a javascript function which takes in a string and parses it as an associative array.
function getValues(string){
var array_values = new Array();
var pairs_array = string.split('\n');
if(pairs_array[0] == 'SUCCESS'){
window.success = true;
}
for(x=1; x< pairs_array.length; x++){
var parsedValue = '';
//console.log(pairs_array[x] + "<br>");
var pair = pairs_array[x].split('=');
//console.log(pair[1]);
var variable = pair[0];
if(pair[1]){
var value = pair[1];
for(i=0; i< value.length; i++){
var character = value.charAt(i);
if(character == '+'){
parsedValue = parsedValue + character.replace('+', ' ');
}else{
parsedValue = parsedValue + value.charAt(i);
}
}
array_values[variable] = decodeURIComponent(parsedValue);
}else{
array_values[variable] = '';
}
}
return array_values;
}
Then the function is called on the string window.name_value_pairs as follows
var array_callback = getValues(window.name_value_pairs);
for(x in array_callback){
console.log("call" + x + " " + array_callback[x]);
}
Works fine. Now i have been trying to write the function in php because i would prefer it on the server side but it is not working out. I'm not sure if the array values ar getting pushed onto the array because nothing gets returned. heres the php code i have tried:
Note: $results_values is a string
$result_values = $_REQUEST['result_values'];
echo "php array " . getValuesPhp($result_values);
function getValuesPhp($string){
$array_values = array();
$pairs_array = explode("\n",$string);
if($pairs_array[0] == 'SUCCESS'){
$success = true;
echo "TRUE";
}
for($x=1; $x< count($pairs_array); $x++){
$parsedValue = '';
$pair = explode("=",$pairs_array[$x]);
$variable = $pair[0];
if(isset($pair[1])){
$value = $pair[1];
for($i=0; $i< strlen($value); $i++){
$character = $value[$i];
//echo "char \n" . $character;
if(strpos($character, '+') !== false){
//echo "plus";
$parsedValue .= str_replace('+', ' ', $character);
}else{
//echo "hi2";
$parsedValue .= $value[$i];
}
}
echo "\n var " . $variable;
echo "\n parsed " . $parsedValue;
$array_values['" . $variable . "'] = $parsedValue;
//echo "arrayValues " . $array_values['" . $variable . "'];
//array_push($GLOBALS[$array_values]['" . $variable . "'], $parsedValue);
}else{
$array_values['" . $variable . "'] = '';
//array_push($GLOBALS[$array_values]['" . $variable . "'], '');
}
}
//echo "array payment stat" . $array_values['payment_status'];
return $array_values;
}
note: where it says $array_values['" . $variable . "'] this does print out the write result as it goes through the loop however it seems like the array elements are not being added to the array as nothing is returned at the end.
Thanks for any help
Sarah
Update:
#ChrisWillard I would like to return an associative array from the string. the string is in the format where each line is in the form key=value .. it is actually the string which comes back from a paypal pdt response. For example:
SUCCESS
mc_gross=3.00
protection_eligibility=Eligible
address_status=confirmed
item_number1=3
tax=0.00
item_number2=2
payer_id=VWCYB9FFJ
address_street=1+Main+Terrace
payment_date=14%3A26%3A14+May+22%2C+2014+PDT
payment_status=Completed
charset=windows-1252
address_zip=W12+4LQ
mc_shipping=0.00
mc_handling=0.00
first_name=Sam
address_country_code=GB
address_name=Sam+Monks
custom=
payer_status=verified
business=mon%40gmail.com
address_country=United+Kingdom
num_cart_items=2
mc_handling1=0.00
mc_handling2=0.00
address_city=Wolverhampton
payer_email=monks%40gmail.com
mc_shipping1=0.00
mc_shipping2=0.00
tax1=0.00
tax2=0.00
txn_id=3PX5572092U
payment_type=instant
last_name=Monks
address_state=West+Midlands
item_name1=Electro
receiver_email=mon%40gmail.com
item_name2=Dub
quantity1=1
quantity2=1
receiver_id=WHRPZLLP6
pending_reason=multi_currency
txn_type=cart
mc_gross_1=1.00
mc_currency=USD
mc_gross_2=2.00
residence_country=GB
transaction_subject=
payment_gross=3.00
thanks for all your answers and help. it was a combination of two things that caused it to not print.. firstly my silly syntax error (being just new at programming haha I wont go into the logic i had behind this but it did make sense to me at the time haha) $array_values['" . $variable . "'] = $parsedValue; changed to this:
$array_values[$variable] = $parsedValue;
it was also the line
echo "php array" . getValuesPhp($result_values); that caused it not to print.
when i changed this to
print_r(getValuesPhp($result_values)); it printed perfect thanks to #ChrisWillard for this. So here is my final code. A combination of #ChrisWillard answer and #Mark B and #Jdo answers. I also wanted to check first if pair[1] existed and go through each character of pair[1] changing any '+' to a space ' ' if it existed so that it could be read by the user. Now i have found the function to do this for me haha. I'm sure it is not new information for a lot of you but for anyone who doesn't know it is urldecode so you can see below ive commented out the loop that i did not need (going through the characters of the string changing the plus value) and instead ive written: $finished_array[$key] = urldecode($value); thanks for all your help.
$result_values = $_REQUEST['result_values'];
print_r(getValuesPhp($result_values));
function getValuesPhp($string){
$finished_array = array();
$pairs_array = explode("\n",$string);
if($pairs_array[0] == 'SUCCESS'){
$success = true;
//echo "TRUE";
}
for($x=1; $x< count($pairs_array); $x++){
$parsedValue = '';
$pair = explode("=",$pairs_array[$x]);
$key = $pair[0];
if(isset($pair[1])){
$value = $pair[1];
//for($i=0; $i< strlen($value); $i++){
//$character = $value[$i];
//if(strpos($character, '+') !== false){
//$parsedValue .= str_replace('+', ' ', $character);
//}else{
//$parsedValue .= $value[$i];
//}
//}
$finished_array[$key] = urldecode($value);
}else{
$finished_array[$key] = '';
}
}
return $finished_array;
}
This is totally non-sensical:
$array_values['" . $variable . "'] = $parsedValue;
You're literally using " . $variable . " as your array key - remember that '-quoted strings do NOT expand variables.
Why not just
$array_values[$variable] = $parsedValue
From what I can gather, this should get you what you need:
$result_values = $_REQUEST['result_values'];
print_r(getValuesPhp($result_values));
function getValuesPhp($string){
$finished_array = array();
$pairs_array = explode("\n",$string);
if($pairs_array[0] == 'SUCCESS'){
$success = true; ////Not sure what you're trying to do here
}
for($x=1; $x< count($pairs_array); $x++) {
$pair = explode("=",$pairs_array[$x]);
$key = $pair[0];
$value = $pair[1];
$finished_array[$key] = $value;
}
return $finished_array;
}

Can't get this auto-email to work in php. Can you help me?

I'm trying to make this secret santa auto-email script, and it's really confusing me... It doesn't email properly (one person gets a TON of emails, no one else gets any...)
I tried to just change the length on the array in the for loops, did I do it right?
I use the shuffle function and the email function, which seem to work well (aside from the for loop on the email function - did I do that right?). It's the main function I need help on.
Here's the code:
<?php
function twodshuffle($array)
{
// Get array length
$count = count($array);
// Create a range of indicies
$indi = range(1,$count);
// Randomize indicies array
shuffle($indi);
// Initialize new array
$newarray = array($count);
// Holds current index
$i = 0;
// Shuffle multidimensional array
foreach ($indi as $index)
{
$newarray[$i] = $array[$index];
$i++;
}
return $newarray;
}
function email($Name, $Email, $Likes)
{
$to = $Email;
$subject = '[Secret Santa] Happy Lolidays from Santabot 2020! Your match is here!';
$message = "HEY! You are " . $Name ."'s Secret Santa. Isn't that exciting? \r\n\r\nThis is what your match filled in for likes/dislikes: \r\n----------------------------\r\n" . $Likes . "\r\n----------------------------\r\n\r\n\r\nNow get them something nice and thoughtful. We will be swapping sometime around Christmas, so you have a lot of time to put some thought in it.\r\nLet's keep gifts around the $30 mark.\r\n\r\nHappy Lolidays,\r\nDCo's Santabot 2020.\r\n\r\nPS: I have set this up so not even I know the matches nor is a list stored anywhere. DO NOT delete this email if you are at risk of forgetting your match.";
$headers = 'From: Santabot 2020 <santabot2020#mydomain.com>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
sleep(1000);
}
$con = mysql_connect("mysql.myserver.com", "username", "password") or die(mysql_error());
mysql_select_db("lolidays_dco", $con) or die(mysql_error());
$array;
//I just changed this array size now. Is this the right syntax?
for ($i = 1; $i <= array.length() -1; $i++) {
$sql = "SELECT * FROM tbl_data WHERE Number = " . $i;
$result = mysql_query($sql);
$count=mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
$Name = $row['Name'];
$Email = $row['Email'];
$Likes = $row['Likes'];
}
$array[$i] = array("Name" => $Name, "Email" => $Email, "Likes" => $Likes);
}
$array = twodshuffle($array);
$string;
//changed this array length as well, is this the right syntax?
for ($i = 0; $i <= array.length(); $i++) {
if ($i == 2) {
$n = $array['0']["Name"];
$e = $array[$i]["Email"];
$l = $array['0']["Likes"];
email($n, $e, $l);
echo "Email Sent!<br />";
$string = $string . $array[$i]["Name"] . " => " . $array['0']["Name"] . "\r\n";
email('Matches', 'backup#email.com', $string);
}
else {
$j = $i + 1;
$n = $array[$j]["Name"];
$e = $array[$i]["Email"];
$l = $array[$j]["Likes"];
email($n, $e, $l);
echo "Email Sent!<br />";
$string = $string . $array[$i]["Name"] . " => " . $array[$j]["Name"] . "\r\n";
}
}
echo "<strong>Done!</strong>";
?>
You've hard-coded the recipient:
$n = $array['0']["Name"]; <---should be $i, not '0'
$e = $array[$i]["Email"];
$l = $array['0']["Likes"]; <---should be $i, not '0'

Email forwarding in PHP

My following code is tested by my friends. They said its working fine. But I am unable to use it. Can anybody find where the error is.
`
<?php
try
{
// Change to your mail server
$host = "pop.gmail.com";
// Connecting to POP3 email server.
$connection = imap_open("{" . $host . ":995/pop3/notls}", 'someusername#gmail.com', 'somepassword');
// Total number of messages in Inbox
$count = imap_num_msg($connection);
echo $count . " messages found<br />";
// Read Messages in Loop, Forward it to Actual User email and than delete it from current email account.
for ($i = 1; $i <= $count; $i++) {
$headers = imap_headerinfo($connection, $i);
$subject = $headers->subject;
$from = $headers->from[0]->mailbox . '#' . $headers->from[0]->host;
if ($headers->cc[0]->mailbox)
$cc = $headers->cc[0]->mailbox . '#' . $headers->cc[0]->host;
$subject = $headers->subject;
$structure = imap_fetchstructure($connection, $i);
$type = $this->get_mime_type($structure);
// GET HTML BODY
$body = $this->get_part($connection, $i, "");
//$raw_body = imap_body($connection, $i);
$attachments = array();
if (isset($structure->parts) && count($structure->parts)) {
for ($e = 0; $e < count($structure->parts); $e++) {
$attachments[$e] = array('is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '');
if ($structure->parts[$e]->ifdparameters) {
foreach ($structure->parts[$e]->dparameters as $object) {
if (strtolower($object->attribute) == 'filename') {
$attachments[$e]['is_attachment'] = true;
$attachments[$e]['filename'] = $object->value;
} //if (strtolower($object->attribute) == 'filename')
} //foreach ($structure->parts[$e]->dparameters as $object)
} //if ($structure->parts[$e]->ifdparameters)
if ($structure->parts[$e]->ifparameters) {
foreach ($structure->parts[$e]->parameters as $object) {
if (strtolower($object->attribute) == 'name') {
$attachments[$e]['is_attachment'] = true;
$attachments[$e]['name'] = $object->value;
} //if (strtolower($object->attribute) == 'name')
} //foreach ($structure->parts[$e]->parameters as $object)
} //if ($structure->parts[$e]->ifparameters)
if ($attachments[$e]['is_attachment']) {
$attachments[$e]['attachment'] = #imap_fetchbody($connection, $i, $e + 1);
if ($structure->parts[$e]->encoding == 3) {
// 3 = BASE64
$attachments[$e]['attachment'] = base64_decode($attachments[$e]['attachment']);
} //if ($structure->parts[$e]->encoding == 3)
elseif ($structure->parts[$e]->encoding == 4) {
// 4 = QUOTED-PRINTABLE
$attachments[$e]['attachment'] = quoted_printable_decode($attachments[$e]['attachment']);
} //elseif ($structure->parts[$e]->encoding == 4)
} //if ($attachments[$e]['is_attachment'])
if ($attachments[$e]['is_attachment']) {
$filename = $attachments[$e]['filename'];
$filename = $attachments[$e]['name'];
$filecontent = $attachments[$e]['attachment'];
} //if ($attachments[$e]['is_attachment'])
} //for ($e = 0; $e < count($structure->parts); $e++)
} //if (isset($structure->parts) && count($structure->parts))
/**** ****/
/*echo "<pre>";
echo "From: " . $headers->Unseen . "<br />";
echo "From: " . $from . "<br />";
echo "Cc: " . $cc . "<br />";
echo "Subject: " . $subject . "<br />";
echo "Content Type: " . $type . "<br />";
echo "Body: " . $body . "<br />";*/
$mail = new Zend_Mail();
$mail->settype(Zend_Mime::MULTIPART_MIXED);
for ($k = 0; $k < count($attachments); $k++) {
$filename = $attachments[$k]['name'];
$filecontent = $attachments[$k]['attachment'];
if ($filename && $filecontent) {
$file = $mail->createAttachment($filecontent);
$file->filename = $filename;
} //if ($filename && $filecontent)
} //for ($k = 0; $k < count($attachments); $k++)
$mail->setFrom($from);
$mail->addTo('testmail#softmail.me');
if ($cc)
$mail->addCc($cc);
$mail->setSubject($subject);
$mail->setBodyHtml($body);
$mail->send();
// Mark the email messages once read
//imap_delete($mbox, 1);
} //for ($i = 1; $i <= $count; $i++)
// Delete all marked message from current email account.
imap_expunge($mbox);
echo 'If you see this, the number is 1 or below';
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
?>
Please check if you have enabled
extension=php_openssl.dll;
ext in you php.ini. I had faced this problem once and enabling the above extension worked for me.

Categories