Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: I need help about SMTP mail form

  1. #1
    Join Date
    Sep 2013
    Location
    Antalya - Turkey
    Posts
    37
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default I need help about SMTP mail form

    Hi everybody,

    Since couple of days i try to run my contact form on my webpage...This is a html website...

    Here is the adress: http://bbb.antalyabalikcilik.com.tr/contact-us.html

    I couldn't apply SMTP mail form...Can you help me please,fix up this problem...
    I tried every document on internet but its still doesn't send ant email...

    Thanks in advance...

  2. #2
    Join Date
    Jan 2015
    Posts
    78
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default

    When code doesn't work, you need to determine why it doesn't work, so that you can fix the problem with it or write code that uses a method that does work for a given situation. Just trying a bunch of different scripts you find on the web is a waste of time because there may be a common problem, such as something required on the server to interface with a mail server, that none of the code satisfies.

    Since you mentioned SMTP, how have you determined that you need to use SMTP to interface between a php script and a mail server? If you do need to use SMTP, you should use an existing php mailer class, like phpmailer or swiftmailer. Write or find a script you understand and stay with that script until you get it to work.

    If you want help with a php script, you will need to post the code, along with what specific symptoms or errors you get from the code.
    Last edited by DyDr; 03-18-2016 at 04:35 PM.

  3. The Following User Says Thank You to DyDr For This Useful Post:

    volkantr19 (03-19-2016)

  4. #3
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Have you confirmed that you have SMTP enabled on your server? It might be disabled by default (very likely on free or very basic accounts) so it is possible that you will need to ask your web host to turn it on for you.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. The Following User Says Thank You to Beverleyh For This Useful Post:

    volkantr19 (03-19-2016)

  6. #4
    Join Date
    Sep 2013
    Location
    Antalya - Turkey
    Posts
    37
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Thank you for your answers....
    In my country,all of web hosting companies use SMTP mail....They turned off mail() function because of spam emails...
    I have to use SMTP mail and my server enable for SMTP mail...

    This is contact page of my website...

    http://bbb.antalyabalikcilik.com.tr/contact-us.html


    php code
    Code:
    <?php
    if(!session_id()) {
    	session_start();
    }
    error_reporting(0);
    
    if (isset($_REQUEST['action'])) {
        if ($_REQUEST['action'] == "php/contacts-process.php") {
            $ourMail = "volkan19@hotmail.com";
            $pre_messagebody_info = "";
            $errors = array();
            $data = array();
            parse_str($_REQUEST['values'], $data);
    
            $result = array(
                "is_errors" => 0,
                "info" => ""
            );
            if (!empty($errors)) {
                $result['is_errors'] = 1;
                $result['info'] = $errors;
                echo json_encode($result);
                exit;
            }
    }	
    }
    }
    ?>




    html code
    Code:
    <!-- contact form -->
    <div class='grid_col grid_col_8'>
    <div class='ce clearfix'>
    <h3 class="ce_title">Drop us a line</h3>
    <div>
    <div role="form" class="cf" id="cf-f16-p10-o1" lang="en-US" dir="ltr">
    <div class="screen-reader-response"></div>
    <form action="php/contacts-process.php" method="post" class="cf-form contact-form" novalidate="novalidate">
    <p>Name*
    <br />
    <span class="cf-form-control-wrap your-name"><input type="text" name="name" value="" size="107" class="cf-form-control cf-text cf-validates-as-required" aria-required="true" aria-invalid="false" /></span> </p>
    <p>Email*
    <br />
    <span class="cf-form-control-wrap your-email"><input type="email" name="email" value="" size="107" class="cf-form-control cf-text cf-email cf-validates-as-required cf-validates-as-email" aria-required="true" aria-invalid="false" /></span> </p>
    <p>Message
    <br />
    <span class="cf-form-control-wrap your-message"><textarea name="message" cols="107" rows="8" class="cf-form-control cf-textarea" aria-invalid="false"></textarea></span> </p>
    <p>
    <span class="captcha-wrapper">
    <iframe src="php/capcha.php" class="capcha-frame" name="capcha_image_frame"></iframe>
    <input class="verify" type="text" id="verify" name="verify" />
    </span>
    <input type="submit" value="Send" class="cf-form-control cf-submit" />
    </p>
    <div class="cws_msg_box error-box clearfix">
    <div class="icon_section"><i class="fa fa-exclamation"></i></div>
    <div class="content_section">
    <div class="msg_box_title">Error box</div>
    <div class="msg_box_text"></div>
    </div>
    </div>
    </form>
    <div class="email_server_responce"></div>
    </div>
    </div>
    </div>
    </div>
    <!-- / contact form -->



    css code
    Code:
    /*
    - CONTACT FORM
    */
    
    div.cf .cf-form-control-wrap {
        margin-left: 8px;
        text-indent: 0;
    }
    
    form.cf-form>p {
        margin-left: -8px;
        margin-bottom: 0;
        text-indent: 8px;
    }
    
    form.cf-form>p>*:first-child {
        margin-left: 0;
    }
    
    form.cf-form>p:last-child:after {
        clear: both;
        display: table;
        content: "";
    }
    
    .cf-form-control.cf-captchac {
        display: inline-block;
        vertical-align: middle;
    }
    
    .cf .cf-form-control-wrap {
        margin-bottom: 15px;
        display: inline-block;
        max-width: calc(100% - 8px);
    }
    
    .cf label {
        font-weight: 700;
    }
    
    .cf input[type="submit"] {
        float: right;
    }
    
    .cf p {
        text-indent: 0;
    }
    
    span.cf-list-item:first-child {
        margin-left: auto;
    }
    
    .cf-not-valid {
        border-color: #ff6766;
    }
    
    .contact-form p.error {
        color: #ff6766;
        margin-top: 10px;
    }
    
    .contact-form .cws_msg_box {
        display: none;
    }
    
    .contact-form .cws_msg_box p {
        color: #ffffff;
        margin: 0;
    }
    
    div.cf-response-output {
        margin-top: 1.333em;
        margin-left: auto;
        margin-right: auto;
    }
    
    div.cf-response-output:last-child {
        margin-bottom: auto;
    }
    
    .cf-response-output:after {
        content: "";
    }
    
    div.cf-response-output:before {
        font-family: FontAwesome;
        left: 40px;
    }
    
    div.cf-response-output.cf-validation-errors:before {
        content: "\f12a";
    }
    
    div.cf-response-output.cf-mail-sent-ok:before {
        content: "\f164";
    }
    
    div.cf-validation-errors {
        border: none;
    }
    
    .contact-form .captcha-wrapper {
        display: inline-block;
    }
    
    .contact-form .captcha-wrapper iframe {
        display: inline-block;
        float: left;
        width: 120px;
        height: 47px;
        margin-top: -6px;
    }
    
    .contact-form .captcha-wrapper input {
        width: 84px;
    }
    
    .contact-form input.error {
        border-color: #ff6766;
    }
    
    
    /*
    - \CONTACT FORM 7
    */

    js code
    Code:
    /* contact form */
    if (jQuery(".contact-form").length) {
      /**/
      /* contact form */
      /**/
    
      /* validate the contact form fields */      
      jQuery(".contact-form").each(function(){
    
        jQuery(this).validate(  /*feedback-form*/{
            onkeyup: false,
            onfocusout: false,
            errorElement: 'p',
            errorLabelContainer: jQuery(this).find('.msg_box_text'),
            rules:
            {
              name:
              {
                required: true
              },
              email:
              {
                required: true,
                email: true
              },
              message:
              {
                required: true
              },
              verify: {
              	required: true,
              	remote: {
                  url: 'php/check-capcha.php',
                  type: "post",
                  data:
                  {
                      code: function()
                      {	
                          return jQuery('.verify').val();
                      }
                  }
                }
    	      }
            },
            messages:
            {
              name:
              {
                required: 'Please enter your name',
              },
              email:
              {
                required: 'Please enter your email address',
                email: 'Please enter a VALID email address'
              },
              message:
              {
                required: 'Please enter your message'
              },
              verify: {
              	required: 'Please enter Captcha',
              	remote: "Please enter a VALID Captcha"
    	      }
            },
            invalidHandler: function()
            {
              jQuery(this).find(".cws_msg_box.error-box").slideDown('fast');
              jQuery("#feedback-form-success").slideUp('fast');
    
            },
            submitHandler: function(form)
            {   
              jQuery(form).find(".cws_msg_box.error-box").slideUp('fast'); 
              var $form = jQuery(form).ajaxSubmit();
              submit_handler($form, jQuery(form).parent().children(".email_server_responce") );
            }
          });
        })
    
      /* Ajax, Server response */ 
      var submit_handler =  function (form, wrapper){
    
        var $wrapper = jQuery(wrapper); //this class should be set in HTML code
        
        $wrapper.css("display","block");
        var data = {
          action: "email_server_responce",
          values: jQuery(form).serialize()
        };
        //send data to server
        jQuery.post("php/contacts-process.php", data, function(s_response) {
          s_response = jQuery.parseJSON(s_response);
          if(s_response.info == 'success'){
            $wrapper.addClass("message message-success").append('<div class="cws_msg_box success-box clearfix"><div class="icon_section"><i class="fa fa-thumbs-up"></i></div><div class="content_section"><div class="msg_box_title">Success!</div><div class="msg_box_text">Your message was successfully delivered.</div></div></div>');
            $wrapper.delay(5000).hide(500, function(){
              jQuery(this).removeClass("message message-success").text("").fadeIn(500);
              $wrapper.css("display","none");
            });
            jQuery(form)[0].reset(); 
          } else { 
            $wrapper.addClass("cws_msg_box error-box clearfix").append("<div class='icon_section'><i class='fa fa-exclamation'></i></div><div class='content_section'><div class='msg_box_title'>Server fail!</div><div class='msg_box_text'><p> Please try again later!</p></div></div>");
            $wrapper.delay(5000).hide(500, function(){
              jQuery(this).removeClass("cws_msg_box error-box clearfix").text("").fadeIn(500);
              $wrapper.css("display","none");
            });
          }
        });
      return false;
      }
    }

  7. #5
    Join Date
    Jan 2015
    Posts
    78
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default

    Your php code is testing the value in $_REQUEST['action']. The jquery/ajax code is setting action: to be "email_server_responce" (note: responce is misspelled). The php code would need to test for that same value.

    You should also be using $_POST to match how the data is being submitted, rather than $_REQUEST, to avoid problems should you also have, now or in the future, any $_GET or $_COOKIE data with the same index names.

    As to using SMTP with either the phpmailer or swiftmailer classes, there are examples in the documentation on the web sites for those classes.

  8. The Following User Says Thank You to DyDr For This Useful Post:

    volkantr19 (03-19-2016)

  9. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    What about your error logs? Have you checked them to see if any useful error messages have been logged? Might give you a better indication of what the problem could be.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  10. The Following User Says Thank You to Beverleyh For This Useful Post:

    volkantr19 (03-19-2016)

  11. #7
    Join Date
    Sep 2013
    Location
    Antalya - Turkey
    Posts
    37
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    What about your error logs? Have you checked them to see if any useful error messages have been logged? Might give you a better indication of what the problem could be.
    If i push send button,i get any error messages...

  12. #8
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Sorry - I don't understand your reply. If you are getting onscreen errors when you submit, we would need to see those. Similarly, please check the error logs generated at server-level (you may need to check your CPanel or ask your web host where they are) because they should give more information than anything shown on screen.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  13. #9
    Join Date
    Sep 2013
    Location
    Antalya - Turkey
    Posts
    37
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    Sorry - I don't understand your reply. If you are getting onscreen errors when you submit, we would need to see those. Similarly, please check the error logs generated at server-level (you may need to check your CPanel or ask your web host where they are) because they should give more information than anything shown on screen.
    When i submit this form,i am getting no errors on screen...

  14. #10
    Join Date
    Jan 2015
    Posts
    78
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default

    I have two recommendations. The first one changes your current code to submit the form data identically when using ajax or if directly using a form. The second one will allow you to easily develop and test the email portion of your code.

    1) Make the following changes to your existing code -

    Add a hidden field to the form that sets up the submitted action value - <input type='hidden' name='action' value='email_server_response'> (note: I corrected the spelling of 'response' and the php code would need to be changed to match.)

    Change the javascript for var data from this -
    Code:
        var data = {
          action: "email_server_responce",
          values: jQuery(form).serialize()
        };
    To this -
    Code:
        var data = jQuery(form).serialize();
    Remove the following two lines from the php code -
    PHP Code:
    $data = array();
    parse_str($_REQUEST['values'], $data); 
    This change makes the action value, that gets submitted, come from the form itself. All the form data is then directly available in $_POST variables - $_POST['action'], $_POST['name'], $_POST['email'], $_POST['message'], and $_POST['verify'] (I'm guessing your code should use the verify field value to match up with a session value from the captcha code?)


    2) Create a new page that just has a basic html form on it, with the action, name, email, message, and verify fields, that submits to - php/contacts-process.php. This will let you directly see any output from contacts-process.php. You should also have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying all the errors it detects.


    Lastly, I'm assuming that you researched either the phpmailer or swiftmailer classes and added php code to actually try to send the email? The code you have posted so far DOESN'T contain anything that would send an email.

Similar Threads

  1. Replies: 1
    Last Post: 06-26-2015, 12:16 PM
  2. Send Mail Using SMTP
    By cristopher in forum PHP
    Replies: 0
    Last Post: 01-31-2013, 10:54 AM
  3. Replies: 1
    Last Post: 03-24-2010, 06:25 PM
  4. Replies: 1
    Last Post: 09-17-2009, 10:00 PM
  5. Mail Form help with <form > and onSubmit
    By Traveler in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 10-14-2007, 05:30 PM

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
  •