Avatar billede anderslund78 Praktikant
02. juni 2005 - 11:55 Der er 5 kommentarer og
1 løsning

Email funktion

Kan nogle hjælpe mig med at komme i gang med denne opgave:

Write a function for notifying a user by email when the change in a currency rate has exceeded the notification threshold. The function should take five arguments:

1. $email: The users email adress.
2. $name: The users name
3. $cid: The currency id for the currency
4. $currentrate: The current currency rate for the currency
5. $chng: The change in percentage between the last notified rate for the currency and the current rate for the currency. The value of $chng can be either positive or negative:

Here is an example email sent to a user of the Currency Alert system:

To: andelu$itu.dk
Subject: uSD currency rate has increased
From: CurrencyWatch
Date: Tue, 04 Jan 2005 16:25:01 +0100

Dear Anders Lund

The USD currency rate is now 556.31 (relative to Danish Kroner). The USD currency rate has increased 11.26 percent since last notification.

Best regards
Currencywatch.dk

Notice: Which of the terms "increased" or "decreased" is used should depend on whether $chng is positive or negative. It can be assumed that $chng is either positive or negative. The function should make use of the built-PHP function mail to send the email.

Er der nogle der har nogle løsningsforslag - jeg er en temmelig stor php-noob, så jeg er taknemmelig for al slags hjælp.

Anders
Avatar billede neess Nybegynder
02. juni 2005 - 15:39 #1
function ($email,$name,$cid$,$currentrate,$chng)
{
$TEXT="Din klient skal understøtte html";
$besked="din mail besked";
SendMail(
  "info@mail.dk","info mail",        //sender
  $email, $name,  //recipient
  "Valuta ændring",                              //subject
  $TEXT,$besked);
}

function SendMail($From,$FromName,$To,$ToName,$Subject,$Text,$Html){
$OB="----=_OuterBoundary_000";
$IB="----=_InnerBoundery_001";
$Html=$Html?$Html:preg_replace("/\n/","{br}",$Text)
  or die("neither text nor html part present.");
$Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail.";
$From or die("sender address missing");
$To or die("recipient address missing");
 
$headers ="MIME-Version: 1.0\r\n";
$headers.="From: ".$FromName." <".$From.">\n";
$headers.="To: ".$ToName." <".$To.">\n";
$headers.="Reply-To: ".$FromName." <".$From.">\n";
$headers.="X-Priority: 1\n";
$headers.="X-MSMail-Priority: High\n";
$headers.="X-Mailer: My PHP Mailer\n";
$headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n";

//Messages start with text/html alternatives in OB
$Msg ="This is a multi-part message in MIME format.\n";
$Msg.="\n--".$OB."\n";
$Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";

//plaintext section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
// plaintext goes here
$Msg.=$Text."\n\n";

// html section
$Msg.="\n--".$IB."\n";
$Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
$Msg.="Content-Transfer-Encoding: base64\n\n";
// html goes here
$Msg.=chunk_split(base64_encode($Html))."\n\n";

// end of IB
$Msg.="\n--".$IB."--\n";

// attachments
if($AttmFiles){
  foreach($AttmFiles as $AttmFile){
  $patharray = explode ("/", $AttmFile);
  $FileName=$patharray[count($patharray)-1];
  $Msg.= "\n--".$OB."\n";
  $Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n";
  $Msg.="Content-Transfer-Encoding: base64\n";
  $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n";
         
  $Msg.=$FileContent;
  $Msg.="\n\n";
  }
}
 
//message ends
$Msg.="\n--".$OB."--\n";
mail($To,$Subject,$Msg,$headers);   
//syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");
}
Avatar billede anderslund78 Praktikant
04. juni 2005 - 20:14 #2
Tak for dit svar.
Tager funktionen højde for om der skal bruges increased eller decreased?
Anders
Avatar billede neess Nybegynder
16. august 2006 - 21:23 #3
hvad tænker du på ?
Avatar billede anderslund78 Praktikant
17. august 2006 - 08:30 #4
Æhh det er så lang tid siden så det er glemt. LÆg et svar så du kan få dine point :-)
Avatar billede neess Nybegynder
17. august 2006 - 08:43 #5
Jeg har fået point :-)
Avatar billede anderslund78 Praktikant
17. august 2006 - 08:55 #6
ok :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester