Welcome, Guest
  • Author Topic: Sending emails from Flash to more than one account using PHP  (Read 1607 times)

    Jose Luis Skidelsky

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    I'm from Argentina, so sorry if my english is poor.
    Following the suggestions of the tutorial called "Sending email with Flash 5 using PHP, Pearl or ASP", I made the formmail for my site in PHP and it worked perfectly, but I couldn't obtain that the form send more than one e-mail to one account. I tried to do this writting two email accounts separated with a comma in the variable ToEmail, but didn't worked.
    Can anyone help me with this problem?
    Thanks a lot!

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Hi Jose Luis, welcome to the Boards !

    Get rid of the $toName variable, some servers doesn't like it. Use

    Line 2 -> $ToEmail = "jeff@snowvids.com, pepe@othersite.com";

    Then in the mail command

    Line 8 ->  mail($ToName,$ToSubject, $Message, "From: ".$FirstName." <".$Email.">");

    More details about mail command on http://es2.php.net/manual/es/function.mail.php

    Jorge
    PD: Yo también soy de Argentina :)


    Jose Luis Skidelsky

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    Hi, Jorge:
    Thank you for your answer. Unfortunately, the changes you suggested didn't work, but I read the tutorial you've recommended me at http://es2.php.net/manual/es/function.mail.php, that helped me to configure the formmail to send emails to multiple accounts. The only thing that doesn't works now is that I receive the emails with the sender "Apache" instead of the variable $FirstName. Do you know why?
    This is the script that I'm using now:

    <?
    $ToEmail = "somebody@somesite.com" . ", " ;
    $ToEmail .= "another@somesite.com";

    $ToSubject = "Contact";

    $EmailBody = "Sent by: $FirstName\nEmail: $Email\nCompany: $Company\nTelephone: $Telefono\n\nMessage:\n$ToComments\n\n";

    $EmailFooter="\nThis email was sent by: $FirstName from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at www.somesite.com";

    $Message = $EmailBody.$EmailFooter;

    mail($ToEmail,$ToSubject, $Message);


    Print "_root.EmailStatus=Complete.";

    ?>


    Thank you!

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    This tutorial is old, and current version of PHP use globals variables as off. That means that if Flash sends a variable named from trough POST, you can't use it like this:

    $from

    but

    $from = &_POST['from'];

    Servers with PHP 4.1 or higher needs this fix. Check details on http://www.flash-db.com/Board/index.php?board=4;action=display;threadid=7713

    Jorge

    Jose Luis Skidelsky

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    Jorge:
    I'm sorry, but I'm an absolute beginner using PHP. Could you tell me wich sentence I have to change in my script?
    Thanks a lot!!

    vesa kortelainen

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 3450
      • View Profile
    Hi Jose, try
    [script]
    $ToEmail = "somebody@somesite.com" . ", " ;
    $ToEmail .= "another@somesite.com";

    $ToSubject = "Contact";

    $EmailBody = "Sent by: $_POST['FirstName']\nEmail: $_POST['Email']\nCompany: $_POST['Company']\nTelephone: $_POST['Telefono']\n\nMessage:\n$_POST['ToComments']\n\n";

    $EmailFooter="\nThis email was sent by: $_POST['FirstName'] from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at www.somesite.com";

    $Message = $EmailBody.$EmailFooter;

    mail($ToEmail,$ToSubject, $Message);


    Print "_root.EmailStatus=Complete.";

    ?>
    [/script]

    Have fun with learning PHP & Flash!

    bpat1434

    • Mods
    • Senior Programmer
    • *****
    • Posts: 419
    • Never Miss An Opportunity To Be Great.
      • MSN Messenger - bpat1434@hotmail.com
      • AOL Instant Messenger - bpat1434
      • Yahoo Instant Messenger - bpat1434
      • View Profile
      • bPatterson
    Jose:

    PHP 4.1 and higher have globals off as a security measure.  You can google and read about that.  A work around is to bind a variable with the value you receive from the posts.  So...

    If your form (in HTML) looks like:
    Code: [Select]
    <form name="contact" action="script.php" method="POST">
    Then you can call ALL data submitted in that form in one of two ways:

    Using the POST Method:
    If data is POSTed to a website, it is sent without the users knowledge, or visibility.  i.e. you will NOT get a url of http://www.domain.com/index.php?var=Skeyn38n1l396ngl3891nl193n4.39n`.3895n92
    Rather, you will get a regular url, and all the data is passed in the header in an array.

    Using the GET Method:
    If data is posted to a script via the GET method, then all value=data pairs will be visible via the URL. i.e. http://www.domain.com/index.php?var=Skeyn38n1l396ngl3891nl193n4.39n`.3895n92
    This causes security problems for logins and makes things messy.

    So once the user submits the form, it will go to script.php.  This script will then send an email to the specified users.

    So your email script as you show it is:

    <?<br>$ToEmail "somebody@somesite.com" ", " ;<br>$ToEmail .= "another@somesite.com";<br>$ToSubject "Contact";<br>$EmailBody "Sent by: $FirstName\nEmail: $Email\nCompany: $Company\nTelephone: $Telefono\n\nMessage:\n$ToComments\n\n";<br>$EmailFooter="\nThis email was sent by: $FirstName from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at www.somesite.com";<br>$Message $EmailBody.$EmailFooter;<br>mail($ToEmail,$ToSubject$Message);<br><br>Print "_root.EmailStatus=Complete.";<br>?>

    Well, to start things off, you need to specifiy a From person, otherwise you will get "Apache".  So let's add this at the beginning:

    <?<br>/* Get all info sent via form */<br>$firstname $_POST['FirstName'];<br>$email $_POST['Email'];<br>$company $_POST['Company'];<br>$telnum $_POST['Telefono'];<br>$comments $_POST['ToComments'];<br><br>/* Specify the From */<br>$from $firstname." <".$email.">";<br><br>/* Specify other headers */<br>$ToEmail "somebody@somesite.com, " ;<br>$ToEmail .= "another@somesite.com";<br>$ToSubject "Contact";<br><br>/* Write the body, footer, message of the Email */<br>$EmailBody "Sent by: $firstname\nEmail: $dmail\nCompany: $company\nTelephone: $telnum\n\nMessage:\n$comments\n\n";<br><br>$EmailFooter="\nThis email was sent by: $firstname from $_SERVER['REMOTE_ADDR'] If you feel that you recieved this e-mail by accident please contact us at www.somesite.com";<br><br>$Message $EmailBody.$EmailFooter;<br><br>/* Mail the message<br>mail() function takes the following form:<br>  mail("To Email", "Subject", "Message" [, "From", "Additional Headers"]);<br>*/<br>mail($ToEmail$ToSubject$Message$from);<br><br>Print "_root.EmailStatus=Complete.";<br>?>

    Using the above code should work as you wish, with PHP 4.1 and up.

    ~Brett

    Jose Luis Skidelsky

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    Thank you Bret & Vesa. Now I'm testing your suggestions, later I'll post you the results.