SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP forwarding from HTML Form

    I have a Form within my HTML Club Site which works fine. However, as someone new to PHP I am having some difficulty making 2 modifications.

    Present Coding:

    <?php

    $sendTo = "myemail@mysite.com";

    $subject = "Contact from site";

    $headers = "From: " . $_POST["name"] . "<" . $_POST["Email"] .">" . "\r\n";

    $headers .= "Reply-To: " . $_POST["eEmail"] . "\r\n";

    $headers .= "Return-path: " . $_POST["E-mail"];


    $message = "The following information has been submitted by " .$_POST["name"] . "\r\n" . "\r\n" . "E-mail Address : " . $_POST["Email"] . "\r\n" . "First Name : " . $_POST["name1"] . "\r\n" . "Last Name : " . $_POST["name2"] . "\r\n" . "Address 1 : " . $_POST["address1"] . "\r\n" . "Address 2 : " . $_POST["address2"] . "\r\n" . "Zip or Post Code : " . $_POST["post_code"] . "\r\n" . "Comments : " . $_POST["comments"];


    mail($sendTo, $subject, $message, $headers);

    header( 'Location: http://www.mysite.com/thanks.html' ) ;

    ?>

    I would like to send a BCC e-mail to a second recipient. I can send to a second e-mail by changing that first line:

    $sendTo = "myemail@mysite.com,myemail2@mysite.com";

    That also works but I can't get it to BCC:

    My second wish is to send the e-mail back to the person filling in the Form, $_POST["Email"] How is this done?

    Any advice would be most appreciated

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Although I use the swiftmailer library for email (http://swiftmailer.org/), From the PHP manual on the mail function (http://php.net/manual/en/function.mail.php) it says to send a BCC like:
    Code:
    $headers .= 'Bcc: someBCCRecepient@example.com' . "\r\n";
    
    So your page would look something like:
    PHP Code:
    $sendTo "myemail@mysite.com";

    $subject "Contact from site";

    $headers "From: " $_POST["name"] . "<" $_POST["Email"] .">" "\r\n";

    $headers .= "Reply-To: " $_POST["eEmail"] . "\r\n";
    $headers .= 'Bcc:' $BCCAddress"\r\n";

    $headers .= "Return-path: " $_POST["E-mail"]; 
    Now the $BCCAddress could be hardcoded into your PHP page, be pulled from a database, or php session.

    It also is a big no-no to trust $_POST data without escaping it you should do something like:
    PHP Code:
    $cleanEmail htmlentities($_POST["eEmail"]); 
    You should escape all form data and any Input or Output data. This means POST, GET, Session, and Database. You may also want to look at email form validation and some SPAM protection; even a CAPTCHA (http://www.captcha.net/) would help here.

    You can learn more about htmlentities at http://php.net/manual/en/function.htmlentities.php

    Hope this helps,
    Steve
    ictus==""

  3. #3
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    My second wish is to send the e-mail back to the person filling in the Form, $_POST["Email"] How is this done?
    Sorry missed this...

    The mail function returns TRUE if successfully sent so you could do something like:

    PHP Code:
    if(mail($to$subject$message$headers) == 1){
      
    //run the mail code again with the person filling the form's email.
      
    $to      'poster@example.com';
     
    $subject 'the subject';
     
    $message 'some message';
     
    $headers 'From: htmlclub@example.com' "\r\n" .
        
    'Reply-To: me@example.com' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();

      
    mail($to$subject$message$headers);
    } else {
      echo 
    'There was a problem with your mail, please try again.';



    ictus==""


Bookmarks

Posting Permissions

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