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.
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post
    Obviously they will provide an email address to which I can direct - it's just that I do not have it right now and therefore I am unsure about the coding.
    I have 3 loose bits scrabbled together and adjusted to my 'style' but I don't seem to be able to connect them to correspond...still have so much to learn hehe

    This is what I got so far:

    // Set email variables
    $email_to = 'info@mail.net';
    $email_subject = 'Feedback';
    ini_set("SMTP","relay-hosting.secureserver.net");
    ini_set("sendmail_from","info@mail.net");
    $header = "Cc: $email";

    // simple email content
    foreach($_POST as $key => $value) {
    if($key != 'submit') $email_content .= $key . ': ' . $value . "\r\n";
    }

    $Cc .= $_POST['email'] == "tick" ? "Copy to yourself: Yes \n" : "Copy to yourself: No \r\n";

    // if validation passed ok then send the email
    mail($email_to, $email_subject, $email_content, $sendmail_from, $headers);


    html:

    <div class="checkbox">
    <input type="checkbox" name="send_cc" value="cc" />
    <div class="label">Send copy to yourself</div>
    </div>


    Am I ever so slightly on the right track or totally lost :P
    Hope you can give me a hint

  2. #17
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yeah this is completely wrong here:
    PHP Code:
     $Cc .= $_POST['email'] == "tick" "Copy to yourself: Yes \n" "Copy to yourself: No \r\n"
    If I get this correctly, the $_POST['email'] is the sender? If so what you want is:
    PHP Code:
    if (isset($_POST['send_cc']))
    {
        
    $sendmail_from .= "Cc: {$_POST['email']}\r\n";

    HTML wise you can make that a lot easier using:
    Code:
    <label class="label"> <!-- do you need to specify this class? -->
        Send copy to yourself
        <input type="checkbox" name="send_cc" value="cc" /> <!-- value doesn't really matter here, we're simply checking existence -->
    </label>
    W3 indicates that is a valid nesting in label despite what I think it looks like. You can also use the label for approach which is what I typically use, but so long as you can contain it in some shape, you can always float the input within label to whichever side you want in the CSS (for which the client developers can probably help you with; it would take me forever to figure that out).

  3. Users who have thanked Fou-Lu for this post:

    Joycie (12-17-2012)

  4. #18
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post
    You lost me a little there...

    The first php code 'tick' I copied from someone...it appeared functional to me, guess i was wrong eh!

    Regarding second php - that refers to the sender indeed.
    so if I understand you correctly, I replace

    ini_set("sendmail_from","info@mail.net");
    $header = "Cc: $email";
    by

    if (isset($_POST['send_cc']))
    {
    $sendmail_from .= "Cc: {$_POST['email']}\r\n";
    }
    Regarding html - the label I added as it was a stubborn piece that didn't want to line up with the checkbox...for sure I am still taking some difficult turns in css styling but eventually I will get wiser ;-)

    I am sorry but the last piece...I have no clue what you're explaining there!
    I've only just started making my first website and straight away got into coding - most terms are still a bit algebra for me. I absolutely love it though and it's amazing what I've learned in the last 2-3 weeks....I WANT MORE!!!! hahaha

    What really puzzles me is how to link the checkbox to the 'send_cc' - any more suggestions?

    You're a great help, thank you so much for taking the time!

  5. #19
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    It already is. The checkbox name is 'send_cc', so when its checked the HTML will send it as a successful form entry to the server. You need to make sure its a part of the form and present before the submit input though. The server then receives that in the method superglobal which in this case (sounds like?) is $_POST['send_cc']. If the form method="get" or has no method specified, then you could find it in $_GET['send_cc']. You can also get the value of send_cc by actually assigning it to something, but that is really only useful if you need to make use of the data (such as creating a list of options to check and storing it in an array).

    You need to choose the name of your variable. Chances are after configuring the smtp and sendmail from directives via INI settings, you do not require the use of the additional parameters in the mail() function call. That is used for sending sendmail configurations (such as -f address@site to represent the sendmail from directive). So I would make use of the variable $headers instead of $sendmail_from as it is ambiguous when it is used for all headers.
    PHP Code:
    ini_set("SMTP","relay-hosting.secureserver.net");
    ini_set("sendmail_from","info@mail.net");

    $email_to 'info@mail.net';
    $email_subject 'Feedback';
    $headers ''// you can put additional stuff here
    $headers .= isset($_POST['send_cc']) ? "Cc: {$_POST['email']}\r\n" '';

    // simple email content
    foreach($_POST as $key => $value) {
    if(
    $key != 'submit'$email_content .= $key ': ' $value "\r\n";
    }

    // if validation passed ok then send the email
    mail($email_to$email_subject$email_content$headers); 
    Like that.
    You'll definitely want to look into validation. Characters to look for in the input are the \r\n (not \n by itself which is fine), you'll want to check that the email provided is just an email and not several emails, and trim off \r\n and \n from all input provided. Look into the use of the filter_var which will help with verifications.

  6. Users who have thanked Fou-Lu for this post:

    Joycie (12-17-2012)

  7. #20
    New Coder
    Join Date
    Dec 2012
    Location
    Spain
    Posts
    24
    Thanks
    15
    Thanked 1 Time in 1 Post
    OMG is there just a 'Thank you' button on the site...I'm looking for the 'Wanna hug you' button!!! Thank you so much! And for the great explanation and advice too you made me a little wiser and a lot happier!

    Thanks a million, it's working perfectly!

    Joyce
    Last edited by vinyl-junkie; 12-18-2012 at 03:18 AM. Reason: signature only allowed through the control panel


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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