/    Sign up×
Community /Pin to ProfileBookmark

send email prob

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’]}rn”;
$from= “From : $name < $email >rn”;
$subject =”$name.com – online shopping orderrn”;

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,’.’, ‘.’) . “nn”;
}

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

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

$to1 = “$emailrn”;
$from1= “From : $name.com < {$row[’email’]} >rn”;
$subject1 =”$name.com – Order ConfiUSDationrn”;

$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,’.’, ‘.’) . “nn”;
}

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

?>

please advise..

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@pnajJan 06.2004 — A possibility ... there seems to be a space between the word 'From' and the colon in both lines ...

$from= "From : $name < $email >rn";

... and ...

$from1= "From : $name.com < {$row['email']} >rn";

All code to do with mail headers is incredibly picky, so maybe take those spaces out!!
Copy linkTweet thisAlerts:
@AliciaauthorJan 07.2004 — 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..
Copy linkTweet thisAlerts:
@pnajJan 07.2004 — It took me a while but I think I've got it!!

The problem is that you are trying to loop through the $result array twice.

But, before you go throught the 2nd 'while' loop, you need to 'reset the array position pointer' back to the start of the array.

So, you want to insert the following line (I've put it in bold just for show):

...

==================

--- Your order ---
==================


";

//$totalCost = "0";

[B]reset($result);[/B]

while($row = mysql_fetch_array($result)) {

...


=================================

An alternative is to try and build both emails during the first 'while' loop.

Another alternative is to run the query again and get a fresh $result array ... but this is pretty inefficient.

Hope that does it!
Copy linkTweet thisAlerts:
@AliciaauthorJan 08.2004 — when i inserted the reset($result), this error displayed:


Warning: reset(): Passed variable is not an array or object in /home/myweb/public_html/cl/perfume/thanks.php on line 123

please advise
Copy linkTweet thisAlerts:
@pnajJan 08.2004 — Did you try the other alternatives?

Please advise.
Copy linkTweet thisAlerts:
@AliciaauthorJan 09.2004 — hi guys,

i have changed my code to check the output but i dun get any output inside the while loop..

my code:

<?

session_start();

$dbServer = "";

$dbUser = "user";

$dbPass = "pass;

$dbName = "my_onlinestore";

global $dbServer;

global $dbUser;

global $dbPass;

global $dbName;

$s = mysql_connect($dbServer, $dbUser, $dbPass) or die("Query failed: $query<br><br>" . mysql_error());

$d = mysql_select_db($dbName, $s) or die("Query failed: $query<br><br>" . mysql_error());


function NewCart()

{

//generate an encrypted string and set it as cookie

if (isset($_COOKIE["cartId"]))

{

return $_
COOKIE["cartId"];

}

else

{

// session_start();

// setcookie("cartId", session_Id(), time() + ((3600 * 24) *7));

return session_id();

//echo "error occurred, please contact administrator or try to use a new cart";
//exit();
}

}

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


$totalCost = "0";

$contents .= "-----n";

$contents .= "Ordern";

$contents .= "-----n";

$cartId = NewCart();

$row = mysql_fetch_array($result);

while($row) {

$totalCost += ($row["qty"] * $row["itemPrice"]);

$contents .="Quantity: {$row['qty']}n";

$contents .="Item: {$row['itemName']}n";

$contents .="Price per item: USD";

$contents .= number_format($row['itemPrice'], 2,'.', '.') . "nn";

}

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

echo $cartId;

echo 'haha -- ';

echo $contents;

echo '<br><br><br><br>';


##################################################################################################


$cartId = NewCart();

$result2 = mysql_query("select* from perfume_cart inner join perfume_items on perfume_cart.itemId = perfume_items.itemId where perfume_cart.cookieId = '".$cartId."' order by perfume_items.itemName asc");



//forcustomer

$contents1 .= "Thanks nn";


$contents1 .= "------------------------------------n";
$contents1 .= "Online Order Formn";
$contents1 .= "------------------------------------n";


$contents1 .= "Your order:n";

$contents1 .= "-----------n";


while($row = mysql_fetch_array($result)) {

$totalCost1 += ($row["qty"] * $row["itemPrice"]);

$contents1 .="Quantity: {$row['qty']}n";

$contents1 .="Item: {$row['itemName']}n";

$contents1 .="Price per item: USD";

$contents1 .= number_format($row['itemPrice'], 2,'.', '.') . "nn";

}

$contents1 .="Total amount: USD {$totalCost1}nn";

echo $cartId;

echo 'haha -- ';

echo $contents1;


?>

is it i have prob with my sql fetch array or my while loop ??? it does work in another file using the same code but not this one..

p.s: actually i wanna send the output to two separate email addresses by using mail function later..

p.p.s: pnaj, what do u mean by building two email addresss in the while loop ?? can u explain a little bit further,, thanks..


please advise..
Copy linkTweet thisAlerts:
@pnajJan 09.2004 — Hi Alicia,

Can't quite see what the problem actually is ... I'll have another look later on and also give you bit more explantion.

Paul.
Copy linkTweet thisAlerts:
@AliciaauthorJan 10.2004 — thanks Paul.. ?
Copy linkTweet thisAlerts:
@pnajJan 10.2004 — Hi Alicia.

Just before I go on, I need a couple of questions answering.

1) What do the variables $name and $email represent? It's a bit confusing ... the way they are being used.

2) The contents of both emails are essntially the same, so why build it twice?

P.
Copy linkTweet thisAlerts:
@AliciaauthorJan 12.2004 — Hi Paul

$name and $email will be passed to this file from one form of another file..

i wanna send two emails because with order info will be sent to me whereas the other one will be sent to the customer (to ask them confirm with the order once again by replying the email)

please advise..

p.s: i am wondering why i can not use $result two times in the while loop ?? i was told that the second time i reuse $result, the variable will be empty.. why is that so ??
Copy linkTweet thisAlerts:
@pnajJan 12.2004 — Ok ... let me see if I've got this right.

Variables below passed to this page by form or whatever ...

$name ... name of the shopper

$email ... email of the shopper

Is that correct?

I've attached a version as a txt file.

If the bit above is correct than it should do the job.Trouble is, I can't debug it properly ... can't get data.

If the bit above isn't correct, then it should be easy to adapt.

Let me know how you get on.

P.

[upl-file uuid=40eb893f-22fe-47cc-acba-662b9a3bf148 size=3kB]mail.txt[/upl-file]
Copy linkTweet thisAlerts:
@AliciaauthorJan 13.2004 — thanks Paul..

oh yeah,, i am wondering is it the brace } is needed when we use more than one double quote in a line of code ???

is some cases, i seen u do add braces there... may i know what actually the purpose of using braces and when we should use it ??

please advise/
Copy linkTweet thisAlerts:
@pnajJan 13.2004 — Hi,

I don't know exactly how to use the braces {} when embedding variables into strings ... because I never embed strings!!

But it's something like ...

$name = "${firstname} Smith".

... equivalent to ...

$name = $firstname." Smith".

... which I prefer.

PS. Was I correct about what $name and $email were? Were they customer details or something else? I really want to know now.

P.
×

Success!

Help @Alicia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...