PDA

View Full Version : I need help about SMTP mail form



volkantr19
03-18-2016, 12:13 PM
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...

DyDr
03-18-2016, 04:25 PM
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.

Beverleyh
03-18-2016, 06:46 PM
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.

volkantr19
03-18-2016, 09:09 PM
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


<?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


<!-- 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


/*
- 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


/* 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;
}
}

DyDr
03-18-2016, 09:34 PM
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.

Beverleyh
03-19-2016, 12:07 AM
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.

volkantr19
03-19-2016, 08:05 AM
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...

Beverleyh
03-19-2016, 08:20 AM
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.

volkantr19
03-19-2016, 10:09 AM
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...

DyDr
03-19-2016, 11:22 AM
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 -

var data = {
action: "email_server_responce",
values: jQuery(form).serialize()
};
To this -

var data = jQuery(form).serialize();

Remove the following two lines from the 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.

Beverleyh
03-19-2016, 12:24 PM
When i submit this form,i am getting no errors on screen...
Try commenting out/removing this line and see if you get any screen errors then;
error_reporting(0);And what about your server logs? These won't be visible on the screen - they are something different. Check your server error logs for clues about script fails.
The error messages found there might offer more insight into the problem.

Have you also tried asking your web host for a small sample test script? Lots of web host FAQs/help guides provide a very basic script to demo email sending.

volkantr19
03-20-2016, 03:53 AM
Finally,i get the message from contact page...I tried everthing during day but i still don't know that how it is fix up...
Last problem is 'success message alert'...
After true or false filling form element,the form doesnt show up success message...

Please check orginal website here: http://html.creaws.com/kiddy/contact-us.html
And my website here: http://bbb.antalyabalikcilik.com.tr/contact-us.html

Which code must be change ?

Beverleyh
03-20-2016, 09:38 AM
Can you confirm if email is now being sent?

If you are NOT receiving a success message because email is NOT being sent, please check your error logs!!! I've given you this advice three times now and you keep avoiding/ignoring it.

volkantr19
03-20-2016, 10:01 AM
Yes i'm sure...I receive email but form doesn't show up success message...
I can confirm it...Please send me an email on contact page...

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

DyDr
03-20-2016, 05:36 PM
I've got to ask why are you doing this task? If it's for leaning, you need to start off with small projects that you can write, test, and debug yourself. If it's for a real project, you need to have a lot more programming and debugging experience before you can do this.

The URL that the jquery .post() method submits to has now been changed to just "'php" in your code. It previously was "php/contacts-process.php". This results in a 403 forbidden error for that part of the javascript code since that's just the name of a folder and you cannot make a request to it without a default document set up. Since this request isn't valid, there is no expected response for the javascript code to use.

Your code is also using a jquery form plugin to submit the form data in this line - var $form = jQuery(form).ajaxSubmit();. This is the line that's actually submitting the form data to the email.php code, but there's no code associated with this to handle the response.

You need to pick just one set of javascrpt code to implement this with.

styxlawyer
03-20-2016, 07:52 PM
... or just do it the easy way with Jotform (www.jotform.com) or FoxyForm (http://www.foxyform.com)!

volkantr19
03-21-2016, 06:44 PM
I've got to ask why are you doing this task? If it's for leaning, you need to start off with small projects that you can write, test, and debug yourself. If it's for a real project, you need to have a lot more programming and debugging experience before you can do this.

The URL that the jquery .post() method submits to has now been changed to just "'php" in your code. It previously was "php/contacts-process.php". This results in a 403 forbidden error for that part of the javascript code since that's just the name of a folder and you cannot make a request to it without a default document set up. Since this request isn't valid, there is no expected response for the javascript code to use.

Your code is also using a jquery form plugin to submit the form data in this line - var $form = jQuery(form).ajaxSubmit();. This is the line that's actually submitting the form data to the email.php code, but there's no code associated with this to handle the response.

You need to pick just one set of javascrpt code to implement this with.

It's for learning...I am a student...I just requested for your help...If i dont ask to somebody,i cant learn something...
I cant do real project because of i am not professional like you...
Thank you so much for your advise...