Jump to content

complex sendmail query


robcrozier

Recommended Posts

ok, im trying to send an automated email to both me and webuser upon successful order completion. However the $message part has to contain if statements and later on for loops. Heres an example of what iv'e got so far.


[code]
$message = "
Order Number : ".$_SESSION['order_no']."
Order Date : ".date("F jS, Y")."
Development time guaranteed : ".
if ($_SESSION['e_commerce_check'] == 'yes')
{
echo ($_SESSION['turnaround_time+e-com']);
}
else
{
echo ($_SESSION['turnaround_time']);
}
." Days

Name : ".$_SESSION['name']."
Address : ".$_SESSION['address1']."
[/code]

then i'll obviously include the variable $message in the sendmail statement :

[code]
mail($to, $subject, $message);
[/code]

though when ran - it does not allow the first 'if' statement, i did expect this like as it is being used within a variable initialisation.  However does anyone have any siggestions as to how i can get round it.

Cheers!
Link to comment
https://forums.phpfreaks.com/topic/26496-complex-sendmail-query/
Share on other sites

Why not calculate the $_SESSION bit before into a different variable:
[code]
if ($_SESSION['e_commerce_check'] == 'yes') {
$check = ($_SESSION['turnaround_time+e-com']);
} else {
$check = ($_SESSION['turnaround_time']);
}
$message = "
Order Number : ".$_SESSION['order_no']."
Order Date : ".date("F jS, Y")."
Development time guaranteed : ".$check." Days

Name : ".$_SESSION['name']."
Address : ".$_SESSION['address1'].";[/code]

Or have I not understood the question?
Yeah that's sorted that 1 out mate cheers, why did i not think of that. lol.
Anyway i wonder if you could help me with a for loop in the same situation. Same code as above but replace the if else block with a for loop which pulls a value out of an array at each pass.  The array value will be stored in a variable like so:

[code]
$variable = $_SESSION['array_value'.$i]
[/code]

The $i variable being the array counter.

There doesn't seem to be any logical way that i can think of to pull all these variables out of the array before the $message assignment.

Can you shed any light?

Thank a lot!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.