Προς το περιεχόμενο

Προτεινόμενες αναρτήσεις

Δημοσ.

Στο site της υπογραφής μου χρησιμοποιώ αυτήν την contact form: http://www.hongkiat.com/blog/ajax-html5-css3-contact-form-tutorial/ και πρόσφατα παρατήρησα πως σταμάτησε να δουλεύει (δεν λαμβάνω τα emails).

 

Επειδή το site είναι σε free hosting (000webhost) υποψιάζομαι πως έχει να κάνει με τον server τους. Τι μπορώ να κάνω για να βρω τι φταίει;

Δημοσ.

Γράψε λίγο τον κώδικα για να δούμε τι γίνεται. Για αρχή πάντως ρώτα τους αν εχουν κάποιο πρόβλημα με τα email service τους

Δημοσ.
php:
<?php 
error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP

//If the form is submitted
if(isset($_POST['submitted'])) {
	
	// require a name from user
	if(trim($_POST['contactName']) === '') {
		$nameError =  'is required'; 
		$hasError = true;
	} else {
		$name = trim($_POST['contactName']);
	}
	
	// need valid email
	if(trim($_POST['email']) === '')  {
		$emailError = 'is required';
		$hasError = true;
	} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
		$emailError = 'You entered an invalid email address.';
		$hasError = true;
	} else {
		$email = trim($_POST['email']);
	}
	
	// require a subject from user
	if(trim($_POST['sub']) === '') {
		$subError =  'is required'; 
		$hasError = true;
	} else {
		$sub = trim($_POST['sub']);
	}
		
	// we need at least some content
	if(trim($_POST['comments']) === '') {
		$commentError = 'is required';
		$hasError = true;
	} else {
		if(function_exists('stripslashes')) {
			$comments = stripslashes(trim($_POST['comments']));
		} else {
			$comments = trim($_POST['comments']);
		}
	}
		
	// upon no failure errors let's email now!
	if(!isset($hasError)) {
		
		$emailTo = '[email protected]';
		$subject = $sub;
		$sendCopy = trim($_POST['sendCopy']);
		$body = "Name: $name \nEmail: $email \nSubject: $sub \nComments: $comments";
		$headers = 'From: ' .' <'.$email.'>' . "\r\n" . 'Reply-To: ' . $email;

		mail($emailTo, $subject, $body, $headers);
        
        // set our boolean completion value to TRUE
		$emailSent = true;
	}
}
?>
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen" border="0"/>
    <!-- @begin contact -->
	<div id="contact" class="section">
		<div class="container content">
		
	        <?php if(isset($emailSent) && $emailSent == true) { ?>
                <p class="info">Thank you, I will contact you soon!</p>
            <?php } else { ?>
            <div id="contact-form">
				<?php if(isset($hasError) || isset($captchaError) ) { ?>
              <!--<p class="alert">Error submitting the form</p>-->
                    <?php } ?>
				
					<form id="contact-us" action="contact.php" method="post">
						<div class="formblock">
							<label class="screen-reader-text">Name <?php if($nameError != '') { ?>
								<span class="error"><?php echo $nameError;?></span>
							<?php } ?> </label>
							<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="txt requiredField" placeholder="" />
					  </div>
                        
						<div class="formblock">
							<label class="screen-reader-text">Email <?php if($emailError != '') { ?>
								<span class="error"><?php echo $emailError;?></span>
							<?php } ?></label>
							<input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="txt requiredField email" placeholder="" />
							
						</div>
                        
                        <div class="formblock">
							<label class="screen-reader-text">Subject <?php if($subError != '') { ?>
								<span class="error"><?php echo $subError;?></span>
							<?php } ?> </label>
							<input type="text" name="sub" id="sub" value="<?php if(isset($_POST['sub']))  echo $_POST['sub'];?>" class="txt requiredField" placeholder="" />
						</div>
                        <br/>
						<div class="formblock">
							<label class="screen-reader-text">Message <?php if($commentError != '') { ?>
							 	<span class="error"><?php echo $commentError;?></span> 
							<?php } ?></label>
							 <textarea name="comments" class="txtarea requiredField" id="commentsText" placeholder=""><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
						</div>
                        <br/>
							<button name="submit" type="submit" class="subbutton">Send</button>
							<input type="hidden" name="submitted" id="submitted" value="true" />
					</form>			
				</div>
				
			<?php } ?>
		</div>
    </div><!-- End #contact -->
    
	

jquery:

<script type="text/javascript">
	<!--//--><![CDATA[//><!--
	$(document).ready(function() {
		$('form#contact-us').submit(function() {
			$('form#contact-us .error').remove();
			var hasError = false;
			$('.requiredField').each(function() {
				if($.trim($(this).val()) == '') {
					var labelText = $(this).prev('label').text();
					$(this).parent().append('<span class="error">  '+labelText+' is required. </span>');
					$(this).addClass('inputError');
					hasError = true;
				} else if($(this).hasClass('email')) {
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					if(!emailReg.test($.trim($(this).val()))) {
						var labelText = $(this).prev('label').text();
						$(this).parent().append('<span class="error">  You have entered an invalid '+labelText+'.</span>');
						$(this).addClass('inputError');
						hasError = true;
					}
				}
			});
			if(!hasError) {
				var formInput = $(this).serialize();
				$.post($(this).attr('action'),formInput, function(data){
					$('form#contact-us').slideUp("fast", function() {				   
						$(this).before('<p class="tick">Thank you! I will contact you soon.</p>');
					});
				});
			}
			
			return false;	
		});
	});
	//-->!]]>
</script>
Δημοσ.

Σου βγάζει "Error submitting the form" ή δείχνει οτι ειναι ολα οκ και απλά δεν έρχεται το mail?

 

Το δεύτερο. Από hosting μου είπαν αυτό:

 

Email using phpmail works because our system suspend lot of mass mail daily.

 

You can test it from http://serverxx.000webhost.com/mailtest.php

 

Note: change serverxx to your server number.

 

However due to the abuse of our service, our servers might be on other site blacklist so your mail might not got deliver and give you the impression that mail is not working

 

You are welcome to create your site to different server or upgrade to paid hosting.

 

smtp server is not available with free hosting, upgrade to paid hosting then you will have access to paid hosting smtp server.

 

Δημοσ.

Στο κομμάτι της javascript, γράφεις στα @@ σου ότι και να σου απαντήσει η php και λες thank you. Είναι και αυτό μια άποψη βέβαια αλλά όχι η πιο σωστή.

$.post($(this).attr('action'),formInput, function(data){
					$('form#contact-us').slideUp("fast", function() {				   
						$(this).before('<p class="tick">Thank you! I will contact you soon.</p>');
					});
				});

θα μπορούσες να εξετάσεις τι έχει το data (ανάλογα με το php output δηλαδή) και να μάθεις κάτι παραπάνω για το τι φταίει.

 

Στη συγκεκριμένη περίπτωση όμως δεν θα αλλάξει κάτι, γιατί και η php απαντάει με τον ίδιο τρόπο (δοκίμασα χωρίς javascript) οπότε δεν υπάρχει κάποιο σφάλμα στη ροή του script.

 

Το email φαντάζομαι το έχεις αλλάξει από [email protected] ?

free host και email είναι όντως ψιλοσίγουρο blacklist για όσους mail server διαβάζουν τέτοιες databases.

  • Like 1
Δημοσ.

Το έχω αλλάξει ναι. Υπάρχει κάποιος άλλος τρόπος να το κάνω να δουλέψει χωρίς να αλλάξω hosting; Μπορώ να βάλω ένα mailto σε ένα link αν είναι, απλά δεν θέλω να φαίνεται η διεύθυνση.

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...