SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple email form keeps sending email to spam folder

    Hi the user fill details and then the email his sent to me the only problem is that the emails keeps going to my spam, can someone help me out please I looked already php website and email format looks the same.
    This is the link to my form.
    http://www.people.eurico.co.uk/

    here my form script
    Code:
    <?php
    
    // Set email variables
    $email_to = 'xxxxx@xxxxxxx.co.uk';
    $email_subject = 'Call back form';
    
    // Set required fields
    $required_fields = array('fullname','email','telephone','comment');
    
    // set error messages
    $error_messages = array(
    	'fullname' => 'Please enter a Name to proceed.',
    	'email' => 'Please enter a valid Email.',
    	'telephone' => 'Please telephone.',
    	'comment' => 'Please enter your Message to continue.' 
    );
    
    // Set form status
    $form_complete = FALSE;
    
    // configure validation array
    $validation = array();
    
    // check form submittal
    if(!empty($_POST)) {
    	// Sanitise POST array
    	foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));
    	
    	// Loop into required fields and make sure they match our needs
    	foreach($required_fields as $field) {		
    		// the field has been submitted?
    		if(!array_key_exists($field, $_POST)) array_push($validation, $field);
    		
    		// check there is information in the field?
    		if($_POST[$field] == '') array_push($validation, $field);
    		
    		// validate the email address supplied
    		if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
    	}
    	
    	// basic validation result
    	if(count($validation) == 0) {
    		// Prepare our content string
    		$email_content = 'peoplesmartlearning.co.uk: ' . "\n\n";
    		
    		// simple email content
    		foreach($_POST as $key => $value) {
    			if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
    		}
    		
    		// if validation passed ok then send the email
    		mail($email_to, $email_subject, $email_content);
    		
    		// Update form switch
    		$form_complete = TRUE;
    	}
    }
    
    function validate_email_address($email = FALSE) {
    	return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
    }
    
    function remove_email_injection($field = FALSE) {
       return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
    }
    
    ?>
    The HTML
    Code:
    <div class="call_us_form">
            		<p class="title">WE'LL CALL YOU BACK</p>
    				<?php if($form_complete === FALSE): ?>
    				<form class="contact_form" id="fm-form" method="post" action="index.php" >
                    <fieldset>
                        <div class="fm-req">
                            <label for="fm-firstname">Name</label>
     <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" />
    <?php if(in_array('fullname', $validation)): ?><script type="text/javascript">alert("Please enter a Name"); history.back();</script><?php endif; ?>
                        </div>
                    
                        <div class="fm-req">
                        <label for="fm-firstname">Email</label>
                     <input type="text" id="email" class="detail" name="email" value=" 
    			<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" />
    			<?php if(in_array('email', $validation)): ?><script type="text/javascript">alert("Please enter a valid Email Address"); history.back();</script><?php endif; ?>
                        </div>
                        
    					<div class="fm-req">
                        <label for="fm-firstname">Number</label>
     <input type="text" id="telephone" class="detail" name="telephone" value="<?php echo isset($_POST['telephone'])? $_POST['telephone'] : ''; ?>" />
     	<?php if(in_array('telephone', $validation)): ?><script type="text/javascript">alert("Please enter telephone number"); history.back();</script><?php endif; ?>
                        </div>
    					
                        <div class="fm-req">
                            <label for="fm-lastname">Message</label>
    <textarea cols="40" rows="5" id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea>
    			<?php if(in_array('comment', $validation)): ?><script type="text/javascript">alert("Please enter your message"); history.back();</script><?php endif; ?>
                        </div>
                    <input class="submit_button" type="submit" value="Call us" />
                    </fieldset>
                </form>
    <?php else: ?>
    <p>Thank you for your Message!</p>
    <p>We will get back to you as soon as we can</p>
    
    <script type="text/javascript">
    	setTimeout ('ourRedirect()', 5000)
    	function ourRedirect () {
    		location.href='index.php'
    		}
    </script>
    <?php endif; ?>

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,096
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    A few things you could try would be:

    - a different subject
    - a fifth parameter in the mail() function. E.g.

    Code:
    mail($email_to, $email_subject, $message, null, '-fwebmaster@example.co.uk');
    That last one is an email address from the same domain as your site. You haven't actually shown us your mail() function.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi the top part is my email function thats all i use to send the email, do you think because i am not using email from my host/website it spam the email that comes from that host. I mean is my site is eurico.co.uk so I have to use the name@eurico.co.uk to receive emails from and I am not allowed to use any other email like an hotmail email thats why it goes to my spam??

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,096
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by macaela View Post
    Hi the top part is my email function thats all i use to send the email
    Sorry, I missed the

    Code:
    mail($email_to, $email_subject, $email_content);
    line in there, so thought your code was incomplete.

    do you think because i am not using email from my host/website it spam the email that comes from that host.
    No, not really. But you should try those suggestions I made. Change your subject, and try changing

    Code:
    mail($email_to, $email_subject, $email_content);
    to

    Code:
    mail($email_to, $email_subject, $email_content, null, '-name@eurico.co.uk');
    Of course, change name to whatever your real email name is.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  5. #5
    SitePoint Mentor silver trophybronze trophy
    Mikl's Avatar
    Join Date
    Dec 2011
    Location
    Edinburgh, Scotland
    Posts
    1,538
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    Since this is your own email folder that the message is addressed to, can you not simply change your spam settings? You should be able to whitelist the user(s) who are sending you the messages.

    Mike

  6. #6
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thanks eevryone for the help. unfortunnaly still not working I tried whitelist the contact didnt work I aslo tried to change the setting ralph.m told and it doesnt even send the email nomore.
    Any other suggestions are greattly appreciated. Please.

  7. #7
    SitePoint Mentor silver trophybronze trophy
    Mikl's Avatar
    Join Date
    Dec 2011
    Location
    Edinburgh, Scotland
    Posts
    1,538
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    Are yo sure that it is only this particular email that is going to spam? Have you tried manually sending an email from another address, just to see if it goes through OK? That would tell you if the fault lies in the way the email is being sent, or whether it's something more generally wrong with your email system.

    Mike

  8. #8
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi yes that is the only email that goes to my spam folder is the one that comes from that contact form this is the whole script you can just copy and paste change the add the email you wish to go to and you will notice it will send it to your own span folder.

    PHP Code:
    <?php

    // Set email variables 
    $email_to 'xxxx@xxxxxx.co.uk'// add your email here
    $email_subject 'Form submission';

    // Set required fields
    $required_fields = array('fullname','email','telephone','comment');

    // set error messages
    $error_messages = array(
        
    'fullname' => 'Please enter a Name to proceed.',
        
    'email' => 'Please enter a valid Email.',
        
    'telephone' => 'Please telephone.',
        
    'comment' => 'Please enter your Message to continue.' 
    );

    // Set Email Headers
    $headers =     'From: you Website <noreply@xxxxx.co.uk>' "\r\n" .
                
    'X-Mailer: PHP/' phpversion() . "\r\n";
    $headers  .= 'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1';

    // Set form status
    $form_complete FALSE;

    // configure validation array
    $validation = array();

    // check form submittal
    if(!empty($_POST)) {
        
    // Sanitise POST array
        
    foreach($_POST as $key => $value$_POST[$key] = remove_email_injection(trim($value));
        
        
    // Loop into required fields and make sure they match our needs
        
    foreach($required_fields as $field) {        
            
    // the field has been submitted?
            
    if(!array_key_exists($field$_POST)) array_push($validation$field);
            
            
    // check there is information in the field?
            
    if($_POST[$field] == ''array_push($validation$field);
            
            
    // validate the email address supplied
            
    if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation$field);
        }
        
        
    // basic validation result
        
    if(count($validation) == 0) {
            
    // Prepare our content string
            
    $email_content 'xxxxxx.co.uk: ' "\n\n";
            
            
    // simple email content
            
    foreach($_POST as $key => $value) {
                if(
    $key != 'submit'$email_content .= $key ': ' $value "\n";
            }
            
            
    // if validation passed ok then send the email
            
    mail($email_to$email_subject$email_content$headers);
            
            
    // Update form switch
            
    $form_complete TRUE;
        }
    }

    function 
    validate_email_address($email FALSE) {
        return (
    preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i'$email))? TRUE FALSE;
    }

    function 
    remove_email_injection($field FALSE) {
       return (
    str_ireplace(array("\r""\n""%0a""%0d""Content-Type:""bcc:","to:","cc:"), ''$field));
    }

    ?>


        <div id="content"><!--start content-->
               <section> <!--START OF SLIDE SHOW-->
            <div id="slide_show"> 
                           
                <div class="call_us_form">
                    <p class="title">WE'LL CALL YOU BACK</p>
                    <?php if($form_complete === FALSE): ?>
                    <form class="contact_form" id="fm-form" method="post" action="index.php" >
                    <fieldset>
                        <div class="fm-req">
                            <label for="fm-firstname">Name</label>
     <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''?>" />
    <?php if(in_array('fullname'$validation)): ?><script type="text/javascript">alert("Please enter a Name"); history.back();</script><?php endif; ?>
                        </div>
                    
                        <div class="fm-req">
                        <label for="fm-firstname">Email</label>
                     <input type="text" id="email" class="detail" name="email" value=" 
                <?php echo isset($_POST['email'])? $_POST['email'] : ''?>" />
                <?php if(in_array('email'$validation)): ?><script type="text/javascript">alert("Please enter a valid Email Address"); history.back();</script><?php endif; ?>
                        </div>
                        
                        <div class="fm-req">
                        <label for="fm-firstname">Number</label>
     <input type="text" id="telephone" class="detail" name="telephone" value="<?php echo isset($_POST['telephone'])? $_POST['telephone'] : ''?>" />
         <?php if(in_array('telephone'$validation)): ?><script type="text/javascript">alert("Please enter telephone number"); history.back();</script><?php endif; ?>
                        </div>
                        
                        <div class="fm-req">
                            <label for="fm-lastname">Message</label>
    <textarea cols="40" rows="5" id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''?></textarea>
                <?php if(in_array('comment'$validation)): ?><script type="text/javascript">alert("Please enter your message"); history.back();</script><?php endif; ?>
                        </div>
                    <input class="submit_button" type="submit" value="Call us" />
                    </fieldset>
                </form>
    <?php else: ?>
    <p>Thank you for your Message!</p>
    <p>We will get back to you as soon as we can</p>

    <script type="text/javascript">
        setTimeout ('ourRedirect()', 5000)
        function ourRedirect () {
            location.href='index.php'
            }
    </script>
    <?php endif; ?>
            </div>      
                   
            
      
                        <div class="clear"></div>

  9. #9
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Malfunctioning of Email

    For the proper functioning of my emails I availed the help of urgentechelp.com. The expertise team of urgentechelp.com possesses sound knowledge on all email related queries and issues. Their services are available at a low cost. The best aspect about urgentechelp.com is that they make a courtesy call after 15 days to check that whether all is fine


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
  •