Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2005
    Posts
    89
    Thanks
    2
    Thanked 0 Times in 0 Posts

    a couple of php email questions

    Hello all,

    I have a php script that processes a web form, sends and email and insert the information into a MySQL database. It all works fine, but I am trying to make some modifications to it and I'm not sure how to do it. I keep making changes and breaking it every time!

    The first thing I am trying to do is change how the email is sent. When the email is sent to the recipient, the sender email address seems to be generated by the web server that the script is sitting on. I was hoping to change it to the email that the user entered with the form ($email). any ideas how this is done?

    The second thing I am trying to do, is have the form sent to two different email addresses. Again I have tried modifying the script but with no success. Any thoughts or suggestions as to how I might do that would be great.

    Heres what me code looks like:

    PHP Code:
    <?php


    // read in variables from form


    $to $to;
    $from $from;
    $email $email;
    $subject "Registration ";
    $address $address;
    $middlename $middlename;
    $lastname $lastname;
    $dateofbirth $dateofbirth;
    $town $town;
    $county $county;
    $country $country;
    $postcode $postcode;
    $telephone $telephone;
    $nickname $nickname;
    $password $password;
    $bigslickprivate $bigslickprivate;
    $bigslickplayers $bigslickplayers;
    $bigslickpreffered $bigslickpreffered;
    $today date ("l, F jS Y");



    // database stuff



    $dbhost 'host in here ';
    $dbuser 'coolhan_admin';
    $dbpass 'wordword';

    $conn mysql_connect($dbhost$dbuser$dbpass) or die                      ('Error connecting to mysql');

    $dbname 'coolhan_bigslickreg';
    mysql_select_db($dbname);

    $sql "INSERT INTO players (dfirstname,dmiddlename,dlastname,demail, ddateofbirth, daddress, dtown, dcounty, dcountry, dpostcode, dtelephone, dnickname, dpassword, dprivateclub, dplayerclub, dpreferredclub) VALUES ('$from','$middlename','$lastname','$email','$dateofbirth','$town','$county','$country', '$postcode','$telephone','$nickname','$password','$bigslickprivate','$bigslickprivate','$bigslickplayers','$bigslickpreffered')";
    $result mysql_query($sql);



    // check that required forms are complete



    if (($to == "") || ($from == "") || ($email == "") || ($subject == "") || ($address == "") || ($middlename == "") || ($lastname == "") || ($dateofbirth == "") || ($town == "") || ($county == "") || ($country == "") || ($postcode == "") || ($telephone == "") || ($nickname == "") || ($password == "") || ($bigslickprivate == "") || ($bigslickplayers == "") || ($bigslickpreffered == "")) {
            
    readfile("blankfields.html");
           exit;
           } else {
           }



    // check email format



    if (($email != "")) {
            
    $locationofat strpos($email'@');
            
    $locationofdot strrpos($email'.');
            if ((
    $locationofat == "0") || ($locationofdot $locationofat) || $locationofdot == "0") {
                    
    readfile("bademail.html");
                    exit;
                    } else {
                    }
    }



    // create the email message



    $msg .= "PLEASE FORWARD THIS EMAIL TO bigslick@website.com \n\n\n";

    if (
    $from != "") {
         
    $msg .= "First Name : $from\n";
         }
    if (
    $middlename != "") {
         
    $msg .= "Middle Name : $middlename\n";
         }
    if (
    $lastname != "") {
         
    $msg .= "Last Name : $lastname\n";
         }
    if (
    $email != "") {
         
    $msg .= "Email : $email\n";
         }
    if (
    $dateofbirth != "") {
         
    $msg .= "Date of Birth : $dateofbirth\n";
         }
    $msg .= "Address : $address\n";

    if (
    $town != "") {
         
    $msg .= "Town : $town\n";
         }
    if (
    $county != "") {
         
    $msg .= "County : $county\n";
         }
    if (
    $country != "") {
         
    $msg .= "Country : $country\n";
         }
    if (
    $postcode != "") {
         
    $msg .= "Postcode : $postcode\n";
         }
    if (
    $telephone != "") {
         
    $msg .= "Telephone : $telephone\n";
         }
    if (
    $nickname != "") {
         
    $msg .= "Nick Name : $nickname\n";
         }
    if (
    $password != "") {
         
    $msg .= "Password : $password\n";
         }
    if (
    $bigslickprivate != "") {
         
    $msg .= "Join the Big Slick Private Members club? : $bigslickprivate\n";
         }
    if (
    $bigslickplayers != "") {
         
    $msg .= "Join the Big Slick Players Club? : $bigslickplayers\n";
         }
    if (
    $bigslickpreffered != "") {
         
    $msg .= "Obtain membership to Big Slick's preferred members club? : $bigslickpreffered\n\n";
         }
    $msg .= "Sent : $today\n";



    // send the email



    $mailheaders "BigSlick Site registration ( $from )<> \n";
    $mailheaders .= "Reply-To: $email\n\n";

    mail($to$subject$msg$mailheaders);



    // pull in the thank you file



    readfile("thankyou.html");

    exit;

    ?>

    Thanks guys,

    John
    Last edited by fogofogo; 04-25-2006 at 02:07 PM.

  • #2
    New Coder
    Join Date
    Sep 2005
    Posts
    89
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I actually figured out a work around thats working fine. Its probably not ideal, but at this point it will have to do.

    if anyone is interested, all I did was take the create email part of the script put it into an include and duplicated it with the other email address variables etc.

    So the other problem is the senders email address. How do I have that appear in the sender field of the email??

    Thanks

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $mailheaders "BigSlick Site registration < $from > \n" 

  • #4
    New Coder
    Join Date
    Sep 2005
    Posts
    89
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •