Jump to content

slawotrend

Members
  • Posts

    17
  • Joined

  • Last visited

Posts posted by slawotrend

  1. 23 hours ago, gizmola said:

    PHP's built in mail() function is designed to dump off mail to a system Mail Transfer Agent (MTA).  It is not a full blown implementation of SMTP with support for SSL etc.  To get that level of functionality, unless you plan to spend a good amount of time writing this to SMTP and Email format RFC standards, it is advisable to use a library.

    The traditional answer to this question involves pointing you to the PHPMailer library.

    PHPMailer source is here:  https://github.com/PHPMailer/PHPMailer

    I am a big fan of things that have come from the Symfony project, and they have an alternative to PHPMailer named Swiftmailer.

    Swiftmailer is here:  https://swiftmailer.symfony.com/docs/index.html

    Either library will do the job for you, so I'd advise you look at both and use whichever one you like the best, or that fits in with your overall project.

     

     

     

    I will probably go for internal mail server with forwarding to Google of the conent from form (the actual email dumped by mail function) I believe this will be much easier to achieve than write complex PHP application I don't have enough experience with yet.  I will maybe test it later for separate SMTP implementation, but setting up an internal email server is straightforward and forwarding message through the form or by setting the email forwarding  on the server may be easily achieved.  PHPMailer or Swiftmailer will do the job, sure but as my form required POST function to enter manually the content that is grabbed in an HTML form from the actual web form and works great for now with current code. I don't see in PHPMailer on how to create email body content that can use sth like POST than can actually bring the manually enetered data from the form to HTML formated email using sth like below.

     

    Every manual of PHPMailer has sth like this

    // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

     

    Which is manually enter predefined email embeded within the code. How to make it working the the dynamic form that is filled with data and is set to $mail as dynamically changed content grabbed into email body from the form and through the form?

     

     

     

  2. 6 hours ago, chhorn said:

    Your post lacks relevant information

    what should this mean to anyone?

    What error messages did you get? What is the actual and the expected behavior?

    Your code is incomplete, you did not say which return values you got or what you tested against.

    ok. Let's make it straigh what I am trying to achieve

     

    For now I am using this which wshould make my code complete

     

    <?php
    /********************************************************************************************************************
    * Main PHP code.
    *********************************************************************************************************************/
    session_start();
    ob_start();
    //ini_set('error_reporting', E_NONE);
    
    if(isset($_POST["submitted"]) && $_POST["submitted"] == 1)
    {
        //Read POST request params into global vars
    
        
        $to_mail           = trim(strip_tags($_POST['sup1'])); // Function to use supplier email on the form
        $to_mail          .= ','. trim(strip_tags($_POST['sup2']));
        $to_mail          .= ','. trim(strip_tags($_POST['sup3']));
        $to_mail          .= ','. trim(strip_tags($_POST['sup4']));
        $quote_rec1        = ','. trim(strip_tags($_POST['rec1']));
        $quote_rec2        = ','. trim(strip_tags($_POST['rec2']));
        $quote_rec3        = ','. trim(strip_tags($_POST['rec3']));
        $quote_rec4        = ','. trim(strip_tags($_POST['rec4']));
        $req_by            = trim(strip_tags($_POST['query']));
        $assigned_to       = trim(strip_tags($_POST['assigned']));        
        $from_email        = trim(strip_tags($_POST['senderemail']));
        $part_no           = trim(strip_tags($_POST['partno']));
        $item_name         = trim(strip_tags($_POST['item']));
        $volume_exp        = trim(strip_tags($_POST['volume']));
        $email_subject     = trim(strip_tags($_POST['subject']));
        $email_message     = nl2br(trim(strip_tags($_POST['message'])));
        $security_code     = trim(strip_tags($_POST['captcha_code']));


        
        
        //Set up the email headers -  the rest code above

     

    And instead of this

    $mailer = mail($to_mail, $email_subject, $email_message, $headers);


    Want to create sth like:

    $mailer =  some function here to use google mail login for the code below to use phpMailer by embending the code below with mine so all can work with PHPMailer

    $mail->isSMTP();
    $mail->Host = 'smtp.googlemail.com';  //gmail SMTP server
    $mail->SMTPAuth = true;
    $mail->Username = 'GMAIL_USERNAME';   //username
    $mail->Password = 'GMAIL_PASSWORD';   //password
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;                    //SMTP port

    My current form works fine for internal email server, however, need it to adapt to external where mail function is and I am slightly confused on how to proceed.

     

     

     

     

     

     

  3. Hello All,

     

    I am strugling with embending standard smtp code within the one I have. As I am using PHP ocassionaly I have problem with this.

     

    My code is to use mail function to send email through an form with email server installed on host system where the form and server are together.

     

    I want this code to adapt to sth that can login to google account and use google external smtp protocol to send the content of the form defined in $headers

     

    The problem is I am using self generated captcha that validates if the email is sent and  all fields are filled (currently under tests what should be filled and not filled) and it works fine

     

    This is my code that works on a local host server:

     

    //Set up the email headers
        
        $headers    = "From: $from_sender <$from_email>\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers   .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers   .= "Message-ID: <".time().rand(1,1000)."@".$_SERVER['SERVER_NAME'].">". "\r\n";

        //Set up the email content
        
        $email_message = '<html><body>';
        $email_message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
        $email_message .= "<tr style='background: #eee;'><td><strong>Request</strong></td></tr>";
        $email_message .= "<tr style='background: #fff;'><td></td><td>" . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Requested By:</strong> </td><td>" . strip_tags($_POST['query']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Assigned To:</strong> </td><td>" . strip_tags($_POST['assigned']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Contact Email:</strong> </td><td>" . strip_tags($_POST['senderemail']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>New Part Number:</strong> </td><td>" . strip_tags($_POST['partno']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Item Description:</strong> </td><td>" . strip_tags($_POST['item']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Expected Annual Volume:</strong> </td><td>" . strip_tags($_POST['volume']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 1:</strong> </td><td>" . strip_tags($_POST['sup1']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec1']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 2:</strong> </td><td>" . strip_tags($_POST['sup2']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec2']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 3:</strong> </td><td>" . strip_tags($_POST['sup3']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec3']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Supplier 4:</strong> </td><td>" . strip_tags($_POST['sup4']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Quotation Received:</strong> </td><td>" . strip_tags($_POST['rec4']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Email Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>";
        $email_message .= "<tr style='background: #eee;'><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
        $email_message .= "</body></html>";

        // Required Fileds Validation
        
        if($req_by == "")
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter your full name.</div>';
        }
        elseif($from_email == "")
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter your email address.</div>';
        }
        elseif(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $from_email))
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter a valid email address.</div>';
        }
        elseif($email_subject == "")
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter the subject.</div>';
        }
        elseif($part_no == "")
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter the part number.</div>';
        }
        elseif($email_message == "")
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter your message.</div>';
        }
        elseif($security_code == "")
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter the security code.</div>';
        }
        elseif(!isset($_SESSION['vpb_captcha_code']))
        {
            $submission_status = '<div class="vpb_info" align="left">Sorry, missing session. Please refresh and try again.</div>';
        }
        else
        {
            if(empty($_SESSION['vpb_captcha_code']) || strcasecmp($_SESSION['vpb_captcha_code'], $_POST['vpb_captcha_code']) != 0)
            {
                //Note: the captcha code is compared case insensitively. If you want case sensitive match, update the check above to strcmp()
                $submission_status = '<div class="info" align="left">Please enter the correct code.</div>';
            }
            else
            {
                $mailer = mail($to_mail, $email_subject, $email_message, $headers);
                        
                if ($mailer)
                 {
                    //Displays the success message when email message is sent
                      $submission_status = "<div align='left' class='success'>The message has been sent successfully!</div>";
                 }
                 else
                 {
                     //Displays an error message when email sending fails
                      $submission_status = "<div align='left' class='info'>Sorry, your email could not be delievered. <br>Please try again or contact website admin.</div>";
                 }
            }
                
        }
    }
    ?>

     

    And would like sth like this in place of $mailer , but my way is not working

    The code I thought would be embeded into $mailer

    $mail->isSMTP();
    $mail->Host = 'smtp.googlemail.com'//gmail SMTP server
    $mail->SMTPAuth = true;
    $mail->Username = 'GMAIL_USERNAME';   //username
    $mail->Password = 'GMAIL_PASSWORD';   //password
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;                    //SMTP port

    Any idea how to adapt it to my code are welcomed and appreciated,

     

    Thanks

     

     

     

  4. I tried to change to this before and it didn't work,

      $to_email          = trim(strip_tags($_POST['sup1'])); // supplier email on the form
        $to_email         .= ','.trim(strip_tags($_POST['sup2']));
        $to_email         .= ','.trim(strip_tags($_POST['sup3']));
        $to_email         .= ','.trim(strip_tags($_POST['sup4']));

    Then:

    $mailer = mail($to_email,  $email_subject, $email_message, $headers);

    The code always sents one email intead of 4. Weird.

    Would there be possible to use array for POST and then enforce to use array in mailer? Maybe this would work.

     

    Thanks for help anyway.

     

     

  5. 1 hour ago, slawotrend said:

    I'm back because the form send only to one address from the form instead to  supplier 1-4 at the same time

    that's my code:

    Help will be great

     

    <?php
    session_start();
    ob_start();
    //ini_set('error_reporting', E_NONE);

    if(isset($_POST["submitted"]) && $_POST["submitted"] == 1)
    {
        //Read POST request params into global vars

        
        $to_email1          = trim(strip_tags($_POST['sup1'])); // supplier email on the form
        $to_email2         .= ','.trim(strip_tags($_POST['sup2']));
        $to_email3         .= ','.trim(strip_tags($_POST['sup3']));
        $to_email4         .= ','.trim(strip_tags($_POST['sup4']));
        $part_no           = trim(strip_tags($_POST['partno']));
        $item_name         = trim(strip_tags($_POST['item']));
        $volume_exp        = trim(strip_tags($_POST['volume']));
        $quote_receipt     = trim(strip_tags($_POST['quote']));
        $from_sender       = trim(strip_tags($_POST['sender']));
        $from_email        = trim(strip_tags($_POST['senderemail']));
        $email_subject     = trim(strip_tags($_POST['subject']));
        $email_message     = nl2br(trim(strip_tags($_POST['message'])));
        $security_code     = trim(strip_tags($_POST['vpb_captcha_code']));
        
        //Set up the email headers
        $headers    = "From: $from_sender <$from_email>\r\n";
        $headers   .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers   .= "Message-ID: <".time().rand(1,1000)."@".$_SERVER['SERVER_NAME'].">". "\r\n";   
        
        if($from_sender == "")

        {
            $submission_status = '<div class="vpb_info" align="left">Please enter your message.</div>';
        }
        elseif($security_code == "")
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter the security code.</div>';
        }
        elseif(!isset($_SESSION['vpb_captcha_code']))
        {
            $submission_status = '<div class="vpb_info" align="left">Sorry, missing session. Please refresh and try again.</div>';
        }
        else
        {
            if(empty($_SESSION['vpb_captcha_code']) || strcasecmp($_SESSION['vpb_captcha_code'], $_POST['vpb_captcha_code']) != 0)
            {
                //Note: the captcha code is compared case insensitively. If you want case sensitive match, update the check above to strcmp()
                $submission_status = '<div class="vpb_info" align="left">Please enter the correct code.</div>';
            }
            else
            {
                $mailer = @mail($to_email1, $to_email2, $to_email3, $to_email4,  $email_subject, $email_message, $headers);
                        
                if ($mailer)
                 {
                    //Displays the success message when email message is sent
                      $submission_status = "<div align='left' class='vpb_success'>The message has been sent successfully!</div>";
                 }
                 else
                 {
                     //Displays an error message when email sending fails
                      $submission_status = "<div align='left' class='vpb_info'>Sorry, your email could not be delievered. <br>Please try again or contact website admin.</div>";
                 }
            }
                
        }
    }
    ?>

     

    Regaring to the problem the code works only for one  $to_email,  any suggestions,  I have properly defined parameters in html and it only works for first $to_email

    HTML is like

    <input type="text" id="sup1" name="sup1" value="<?php echo strip_tags($_POST["sup1"]); ?>"

    <input type="text" id="sup2" name="sup2" value="<?php echo strip_tags($_POST["sup2"]); ?>"

    <input type="text" id="sup3" name="sup3" value="<?php echo strip_tags($_POST["sup3"]); ?>"

    <input type="text" id="sup4" name="sup4" value="<?php echo strip_tags($_POST["sup4"]); ?>"

    I am new  PHP so any example code would help

  6. I'm back because the form send only to one address from the form instead to  supplier 1-4 at the same time

    that's my code:

    Help will be great

     

    <?php
    session_start();
    ob_start();
    //ini_set('error_reporting', E_NONE);

    if(isset($_POST["submitted"]) && $_POST["submitted"] == 1)
    {
        //Read POST request params into global vars

        
        $to_email1          = trim(strip_tags($_POST['sup1'])); // supplier email on the form
        $to_email2         .= ','.trim(strip_tags($_POST['sup2']));
        $to_email3         .= ','.trim(strip_tags($_POST['sup3']));
        $to_email4         .= ','.trim(strip_tags($_POST['sup4']));
        $part_no           = trim(strip_tags($_POST['partno']));
        $item_name         = trim(strip_tags($_POST['item']));
        $volume_exp        = trim(strip_tags($_POST['volume']));
        $quote_receipt     = trim(strip_tags($_POST['quote']));
        $from_sender       = trim(strip_tags($_POST['sender']));
        $from_email        = trim(strip_tags($_POST['senderemail']));
        $email_subject     = trim(strip_tags($_POST['subject']));
        $email_message     = nl2br(trim(strip_tags($_POST['message'])));
        $security_code     = trim(strip_tags($_POST['vpb_captcha_code']));
        
        //Set up the email headers
        $headers    = "From: $from_sender <$from_email>\r\n";
        $headers   .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers   .= "Message-ID: <".time().rand(1,1000)."@".$_SERVER['SERVER_NAME'].">". "\r\n";   
        
        if($from_sender == "")

        {
            $submission_status = '<div class="vpb_info" align="left">Please enter your message.</div>';
        }
        elseif($security_code == "")
        {
            $submission_status = '<div class="vpb_info" align="left">Please enter the security code.</div>';
        }
        elseif(!isset($_SESSION['vpb_captcha_code']))
        {
            $submission_status = '<div class="vpb_info" align="left">Sorry, missing session. Please refresh and try again.</div>';
        }
        else
        {
            if(empty($_SESSION['vpb_captcha_code']) || strcasecmp($_SESSION['vpb_captcha_code'], $_POST['vpb_captcha_code']) != 0)
            {
                //Note: the captcha code is compared case insensitively. If you want case sensitive match, update the check above to strcmp()
                $submission_status = '<div class="vpb_info" align="left">Please enter the correct code.</div>';
            }
            else
            {
                $mailer = @mail($to_email1, $to_email2, $to_email3, $to_email4,  $email_subject, $email_message, $headers);
                        
                if ($mailer)
                 {
                    //Displays the success message when email message is sent
                      $submission_status = "<div align='left' class='vpb_success'>The message has been sent successfully!</div>";
                 }
                 else
                 {
                     //Displays an error message when email sending fails
                      $submission_status = "<div align='left' class='vpb_info'>Sorry, your email could not be delievered. <br>Please try again or contact website admin.</div>";
                 }
            }
                
        }
    }
    ?>

     

  7. 2 minutes ago, ginerjm said:

    NO YOU CAN'T.   You have to reference each item from the form with its real name.  $_POST['email1'], $_POST['email2'], etc....

    As in:

    $to_mail1 = trim(strip_tags($_POST['mailaddress1']));

    $to_mail2 = trim(strip_tags($_POST['mailaddress2']));

    Then use the new vars $to_mail1 and $to_mail2 later from then on.

    If you are not sending your email as an html email you don't want to use nl2bt function on the data.

    different way of my thinking and makes sense thanks. Now I've got it.

  8. 3 minutes ago, ginerjm said:

    I'd like to point out that you have to use a "from" address that exists on your server/domain.  It won't (probably) send something that has a "fake" from address - it has to be a legitimate one that your domain recognizes.

    As for the to address.  You have to take each input value (post) and clean it and add it to the to address.

    $to_email = trim($_POST['email1']);

    $to_email .= ','.teim($_POST['email2']);

    $to_email .= ','.trim($_POST['email3']);

    (Note the .= usage)

    Thx will do like this, I am going to set all to smtp that doesn't require own email server and domain, but not at this stage yet. How to do with my previous reply to gw1500 i mean to send all content on the form within email message , I have suggested if can do sth like $email_message     = nl2br(trim(strip_tags($_POST['mailaddress3, mailaddress4, email, subject, message'])));  but not sure

  9. I got you regarding $to email.

     

    $to_email   = trim(strip_tags($_POST['mailaddress1, mailaddress2, mailaddress3']));

     

     

     

    now, I want to grab all HTML form or text within all fields and submit it as HTML email not only the text/message field I have.

    should I do sth like this?

    PHP example part  (supplier2 and 3 is mailaddress2 and 3 in post )

       

    $email_message     = nl2br(trim(strip_tags($_POST['mailaddress3'])));

    $email_message     = nl2br(trim(strip_tags($_POST['mailaddress4'])));

    $email_message     = nl2br(trim(strip_tags($_POST['email'])));

    $email_message     = nl2br(trim(strip_tags($_POST['subject'])));

    $email_message     = nl2br(trim(strip_tags($_POST['message'])));

    $security_code     = trim(strip_tags($_POST['vpb_captcha_code']));
        
        //Set up the email headers
        $headers      = "From: $from_fullname <$from_email>\r\n";
        $headers   .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers   .= "Message-ID: <".time().rand(1,1000)."@".$_SERVER['SERVER_NAME'].">". "\r\n";  

    if(empty($_SESSION['captcha_code']) || strcasecmp($_SESSION['vcaptcha_code'], $_POST['captcha_code']) != 0)
            {
                //Note: the captcha code is compared case insensitively. If you want case sensitive match, update the check above to strcmp()
                $submission_status = '<div class="info" align="left">Please enter the correct code.</div>';
            }
            else
            {
                $vasplus_mailer_delivers_greatly = @mail($to_email, $email_subject, $email_message, $headers);
                        
                if ($vasplus_mailer_delivers_greatly)
                 {
                    //Displays the success message when email message is sent
                      $submission_status = "<div align='left' class='vpb_success'>The message has been sent successfully!</div>";

     

     

     

    thx

     

    Untitledrheruihuirh.png

  10. should it be sth like this where $to email and $from email are like:

     

    let's say HTML

    <div style="width:400px; text-align: left; float: left; height: 34px;"><input type="text" id="emailaddress1" name="Supplier1" value="" class="input_fields" /></div>

    <div style="width:400px; text-align: left; float: left; height: 34px;"><input type="text" id="emailaddress2" name="Supplier1" value="" class="input_fields" /></div>

    <div style="width:400px; text-align: left; float: left; height: 34px;"><input type="text" id="emailaddres3" name="Supplier1" value="" class="input_fields" /></div> 

     

    and PHP part

     

      $to_email   = trim(strip_tags($_POST['mailaddress1']));

      $to_email   = trim(strip_tags($_POST['emailaddres2']));

      $to_email   = trim(strip_tags($_POST['email address3']));
     

     

    So basically when in HTML form the email will be set by manual entry the POST will use it?

     

     

  11. I have already done my part and it works for standard fixed sender email address like this:

     

    if(isset($_POST["submitted"]) && $_POST["submitted"] == 1)
    {
        //Read POST request params into global vars
        $to_email          = "info@email.com"; // I want here the manual entry on HTML form that will replaced fixed email with the one entered on the form
        $from_fullname     = trim(strip_tags($_POST['emailaddress']));
        $from_email        = trim(strip_tags($_POST['email']));
        $email_subject     = trim(strip_tags($_POST['subject']));
        $email_message     = nl2br(trim(strip_tags($_POST['message'])));
        $security_code     = trim(strip_tags($_POST['vpb_captcha_code']));

    Please see the form I have in HTML in the pic attached

     

    Any suggestions?

     

    html is like this

     

    <div style="width:400px; text-align: left; float: left; height: 34px;"><input type="text" id="emailaddress" name="Supplier1" value="" class="input_fields" /></div>

     

     

    Untitledkhhghg.png

  12. Hello Guys,

     

    I need your help as many PHPers here is more experienced in PHP coding than me.

    I have specific project I am working on and need a piece of code that can send an email from HTML form using PHP to the email address that is entered manually on the form, instead of standard sent to PHP code that is fixed within PHP script and executed during submission.

    I want sth that can grab manually enetered recipient's e-mail address, paste it to the PHP code and then use it to send the email to the recipient, instead of fixed sent to code.  Something would say dynamically changed during the entry that can inject into PHP code the new address email entered on the form and then submit to it.

    Any ideas will be great.

     

    Thanks.

     

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.