sending mail prob

A

Anonymous

Guest
Hi guys,

i am trying to send out this email by using mail function.. i can receive the email that i sent out but there is no sender information displayed.. in other words, the header for From doesn't seem to work.. did i use the from header in the wrong way ??

besides of that, one of the email i received contains item and price per item info but another one (confirmation) is not working at all.. actually the code used to send two emails are the same... i just change the variables by adding '1'... is it the variable scope prob ??? is that so, what can i do to make it right ?

in the confirmation email, the email and the phone value i fetch from the db are not shown in the email as well,, why is that so ???

my code:
<?
include_once "include/db.php";

global $totalCost;

$result = mysql_query("select* from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '".GetCartId()."' order by items.itemName asc") or die (mysql_error());

$result2 = mysql_query("SELECT * FROM info WHERE `username` = '$name'") or die(mysql_error());
$row = mysql_fetch_array($result2);


$to = "{$row['email']}\r\n";
$from= "From : $name < $email >\r\n";
$subject ="$name.com - online shopping order\r\n";

while($row = mysql_fetch_array($result)) {
$totalCost += ($row["qty"] * $row["itemPrice"]);

$contents .="Quantity: {$row['qty']}\n";
$contents .="Item: {$row['itemName']}\n";
$contents .="Price per item: RM";
$contents .= number_format($row['itemPrice'], 2,'.', '.') . "\n\n";
}

$contents .="Total amount: USD {$totalCost}\n";

mail($to,$subject,$contents,$from);

$to1 = "$email\r\n";
$from1= "From : $name.com < {$row['email']} >\r\n";
$subject1 ="$name.com - Order ConfiUSDation\r\n";

$contents1 ="
Please check ur order and reply to confirm. You may contact us at:";
$contents1 .= $status['email'];
$contents1 .= " or phone";
$contents1 .= $status['phone'];
$contents1 .="


==================
--- Your order ---
==================
";
//$totalCost = "0";
while($row = mysql_fetch_array($result)) {
$totalCost += ($row["qty"] * $row["itemPrice"]);

$contents1 .="Quantity: {$row['qty']}\n";
$contents1 .="Item: {$row['itemName']}\n";
$contents1 .="Price per item: USD";
$contents1 .= number_foUSDat($row['itemPrice'], 2,'.', '.') . "\n\n";
}

$contents1 .="Total amount: USD {$totalCost}\n";
mail($to1,$subject1,$contents1,$from1);

?>


please advise..
 
header format

Code:
<?php
mail("nobody@example.com", "the subject", $message,
     "From: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
     "Reply-To: webmaster@{$_SERVER['SERVER_NAME']}\r\n" .
     "X-Mailer: PHP/" . phpversion());
?>
shoulde be
From: ...
not
From :...

refer for more detail on mail function at php.net

use this style
Code:
if(mail($args){
  echo "Mail sent!";
}else{
  echo "Error sending mail!";
}
 
thank you.. now the from issue is fixed..

can u guys give me an idea why in my confirmation email section (Your Order), quantity, item and price is not shown in the email(only show total cost) whereas the other one do show everything,,,

is it the variable scope prob ??? is that so, please advise what i should do..
 
Code:
==================
--- Your order ---
==================
";
//$totalCost = "0";
$contents1="";
while($row = mysql_fetch_array($result)) {
$totalCost += ($row["qty"] * $row["itemPrice"]);

$contents1 .="Quantity: {$row['qty']}\n";
$contents1 .="Item: {$row['itemName']}\n";
$contents1 .="Price per item: USD";
$contents1 .= number_foUSDat($row['itemPrice'], 2,'.', '.') . "\n\n";
}

$contents1 .="Total amount: USD {$totalCost}\n";
mail($to1,$subject1,$contents1,$from1);
try this code //declared $contens1


Code:
<?php
$i=0;
#$c="";
for ($i=0;$i<5;$i++){
$c .="a,";

}
$c .=" Added";
echo "Comments :".$c;

?>
I tested this code whether I declare or not variable $c before for loop the output was same
:roll:
 
sigix said:
Code:
<?php
$i=0;
#$c="";
for ($i=0;$i<5;$i++){
$c .="a,";

}
$c .=" Added";
echo "Comments :".$c;

?>
I tested this code whether I declare or not variable $c before for loop the output was same
:roll:

If you have error reporting set to E_ALL (and as a developer, you really should), this will generate a Notice. It's a bad practice to access/modify variables before they're declared. PHP is smart enough to know how to clean up after sloppy programming like this, but it still shouldn't be done. However, it's definitely not necessary to initialize $i before the for() loop, because $i is initialized within the statement itself (unlike, for example, C). Here's some revised, correct code:

Code:
<?php
$c = '';
for($i = 0; $i < 5; $i++) {
   $c .= 'a,';
}
$c .= ' Added';
echo 'Comments :' . $c;

?>

And as a matter of style only:
a) Why are you so terrified of whitespace? Let's try to make our code more readable, not less readable.
b) Don't use double-quotes when single quotes will do the job! Double quotes make PHP do extra work that's wasted when you don't need to parse variables (you should be using string concatenation for this 95% of the time, btw) or escape characters (e.g. "\n").
 
it is not working even i declared the variable,, it only works when i add the sql query once again before the while loop..

i was told that put twice same query code is not a good idea.. may i know why ??? since this way is working, so should i leave it like that or figure out other way the accomplish the task..

p.s: why when i use back the same code and test it in other file, it doesn't work anymore ??? is it due to the while loop or variable scope ??

please advise.
 
Alicia said:
it is not working even i declared the variable,, it only works when i add the sql query once again before the while loop..

please advise.

Alicia your Code said:
Code:
<? 
include_once "include/db.php"; 

global $totalCost; 

$result = mysql_query("select* from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '".GetCartId()."' order by items.itemName asc") or die (mysql_error()); 

$result2 = mysql_query("SELECT * FROM info WHERE `username` = '$name'") or die(mysql_error()); 
$row = mysql_fetch_array($result2); 


$to = "{$row['email']}\r\n"; 
$from= "From : $name < $email >\r\n"; 
$subject ="$name.com - online shopping order\r\n"; 

while($row = mysql_fetch_array($result)) { 
$totalCost += ($row["qty"] * $row["itemPrice"]); 

$contents .="Quantity: {$row['qty']}\n"; 
$contents .="Item: {$row['itemName']}\n"; 
$contents .="Price per item: RM"; 
$contents .= number_format($row['itemPrice'], 2,'.', '.') . "\n\n"; 
} 

$contents .="Total amount: USD {$totalCost}\n"; 

mail($to,$subject,$contents,$from); 

$to1 = "$email\r\n"; 
$from1= "From : $name.com < {$row['email']} >\r\n"; 
$subject1 ="$name.com - Order ConfiUSDation\r\n"; 

$contents1 =" 
Please check ur order and reply to confirm. You may contact us at:"; 
$contents1 .= $status['email']; 
$contents1 .= " or phone"; 
$contents1 .= $status['phone']; 
$contents1 .=" 


================== 
--- Your order --- 
================== 
"; 
//$totalCost = "0"; 
while($row = mysql_fetch_array($result)) { 
$totalCost += ($row["qty"] * $row["itemPrice"]); 

$contents1 .="Quantity: {$row['qty']}\n"; 
$contents1 .="Item: {$row['itemName']}\n"; 
$contents1 .="Price per item: USD"; 
$contents1 .= number_foUSDat($row['itemPrice'], 2,'.', '.') . "\n\n"; 
} 

$contents1 .="Total amount: USD {$totalCost}\n"; 
mail($to1,$subject1,$contents1,$from1); 

?>

I see that you are trying to get the $row fetch again from the same $result, as you have done it earlier, your $row would be empty the second time and hence the query second time is working.. :D

Hope that is what was nagging you!
 
may i know why the second time i try to get the value to $row, it will be empty ???

is that mean everytime when i wanna reuse the $row (mysql_fetch_array()), i would have to reinsert the sql query code there ??

please advise
 
thanx swirlee
when there are large projects then such small points do matter
 
Alicia said:
may i know why the second time i try to get the value to $row, it will be empty ???
is that mean everytim when i wanna reuse the $row (mysql_fetch_array()), i would have to reinsert the sql query code there ??
please advise
the second while loop that you are using is to confirm the order.
why don't you format the variables in first while loop for both emails.
Code:
<?
include_once "include/db.php";

global $totalCost;

$result = mysql_query("select* from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '".GetCartId()."' order by items.itemName asc") or die (mysql_error());

$result2 = mysql_query("SELECT * FROM info WHERE `username` = '$name'") or die(mysql_error());
$row = mysql_fetch_array($result2);

//vars for 1st mail
$to = "{$row['email']}\r\n";
$from= "From : $name < $email >\r\n";
$subject ="$name.com - online shopping order\r\n";

// vars for 2nd mail
$to1 = "$email\r\n";
$from1= "From : $name.com < {$row['email']} >\r\n";
$subject1 ="$name.com - Order ConfiUSDation\r\n";

$contents1 ="
Please check ur order and reply to confirm. You may contact us at:";
$contents1 .= $status['email'];
$contents1 .= " or phone";
$contents1 .= $status['phone'];
$contents1 .="


==================
--- Your order ---
==================
";

while($row = mysql_fetch_array($result)) {
$totalCost += ($row["qty"] * $row["itemPrice"]);
//body for 1stmail
$contents .="Quantity: {$row['qty']}\n";
$contents .="Item: {$row['itemName']}\n";
$contents .="Price per item: RM";
$contents .= number_format($row['itemPrice'], 2,'.', '.') . "\n\n";

//body for 2nd mail
$contents1 .="Quantity: {$row['qty']}\n";
$contents1 .="Item: {$row['itemName']}\n";
$contents1 .="Price per item: USD";
$contents1 .= number_foUSDat($row['itemPrice'], 2,'.', '.') . "\n\n";

}
//1st mail
$contents .="Total amount: USD {$totalCost}\n";
mail($to,$subject,$contents,$from);

//2nd mail
$contents1 .="Total amount: USD {$totalCost}\n";
mail($to1,$subject1,$contents1,$from1);
?>
you got what I am trying to say?
 
yayaya, i got the idea now... ur code looks a lot better,,, =)

i will try it later... thanks a lot..
 
Back
Top