Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts

    php mail From header - only sends email when field is one word

    Hey guys, this is a really weird issue.

    In my contact form I have an input field for Full Name.

    In my php file, I have it set to use the Full Name field for the From part of the headers, but the form ONLY sends an email when one word is inputted into the field. If someone inputs their full name (2 or more words), the form will not send the email.

    Any idea why it would do that?

    Here's my code:

    PHP Code:
    //send the email  
        
    $body $_POST['full_name'] . " sent you the following message via contact form.<br/>\n\n";  
        
    $body .= "<br/><strong>Email Address:</strong>\n" $_POST['email_address'];
        
    $body .= "<br/><strong>Message:  </strong>\n\n" $_POST['input_msg']; 
        
    $to "myemail@gmail.com";
        
    $subject "Contact Form";
        
    $from 'MIME-Version: 1.0' "\r\n";
        
    $from .= 'Content-type: text/html; charset=UTF-8' "\r\n";
        
    $from .= "From: " $_POST['full_name'] . "\r\nReply-To: " $_POST['email_address'] . "\r\nBcc: myemail@gmail.com";
        
    mail($to$subject$body$from); 

  • #2
    New Coder
    Join Date
    Jun 2012
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Here's the form too if that helps:

    Code:
    <form method="post" id="contact_form">
    	<span class="label">Your Name</span><br>
    	<input name="full_name" class="form_input" onfocus="if(this.value==this.defaultValue || this.value==redError)this.value='';$(this).removeClass('error');" onblur="if (this.value=='') this.value = this.defaultValue" />
    	<span class="label">Email</span><br>
    	<input name="email_address" type="text" class="form_input" onfocus="if(this.value==this.defaultValue || this.value==redError)this.value='';$(this).removeClass('error');" onblur="if (this.value=='') this.value = this.defaultValue" />
    	<span class="label">Subject</span><br>
    	<input name="subject" type="text" class="form_input" onfocus="if(this.value==this.defaultValue || this.value==redError)this.value='';$(this).removeClass('error');" onblur="if (this.value=='') this.value = this.defaultValue" />
    	<span class="label">Message</span><br>
    	<textarea name="input_msg" class="form_input" style="height:70px;" id="input_msg" onfocus="if(this.value==this.defaultValue || this.value==redError)this.value='';$(this).removeClass('error');" onblur="if (this.value=='') this.value = this.defaultValue"></textarea>
    	<input name="submit" type="submit" value="Submit" class="floatleft" />
    	<div id="formResponse"></div>
    </form>
    And the Ajax that handles it:

    Code:
    <script type="text/javascript">
                
        var redError;	// Declares variable for red error message text
    
        $(document).ready(function(){ 
             
            //QUICK CONTACT SUBMITTAL - AJAX
            $("#contact_form").submit(function(){  
                
                $('#formResponse').append('<img src="ajax-loader.gif" class="loaderIcon" alt="Loading..." />');
    
                $.ajax({  
                    type: "POST",  
                    url: "postForm.ajax.php",  
                    data: $("#contact_form").serialize(),  
                    dataType: "json",  
    
                    success: function(msg){
                        
                        $("#contact_form [name='" + msg.inputName +"']").removeClass('error');  
                        $("#contact_form [name='" + msg.inputName +"']").removeClass('success');  
                        $("#contact_form [name='" + msg.inputName +"']").addClass(msg.status);  
                        $("#contact_form [name='" + msg.inputName +"']").val(msg.message);
                        $('#contact_form img.loaderIcon').fadeOut(1000);
                        redError = msg.message;
                        
                        if (msg.status == 'success') {
                        //reset form
                         $( '#contact_form' ).each(function(){
                                this.reset();
                            });
                         //alert
                         alert(msg.message)
                        }
                    },  
                    error: function(){  
                        $("#contact_form [name='" + msg.inputName +"']").removeClass('success');  
                        $("#contact_form [name='" + msg.inputName +"']").addClass('error');  
                        $("#contact_form [name='" + msg.inputName +"']").html("There was an error, please try again.");  
                    }  
                });  
    
                //make sure the form doesn't post  
                return false;  
                
            });	//QUICK CONTACT SUBMITTAL END
    
        });
    	</script>

  • #3
    Regular Coder
    Join Date
    Nov 2012
    Posts
    117
    Thanks
    7
    Thanked 12 Times in 12 Posts
    Quote Originally Posted by frickettz View Post
    If someone inputs their full name (2 or more words), the form will not send the email.
    The question is, is it not being sent, or not received? How do you know it's not sending the e-mail, does your mail function return an error? (store the return of your mail function in a variable and echo that or something)

    If it doesn't, the e-mail seems to be sent after all. It is more likely to have ended up in a spam folder of some sort, check your Gmail spam to see if it's there.

    If there's no error ánd the e-mail doesn't end up in spam, check your maillogs (or ask your hostingprovider to check them for you if you don't have access yourself) to see if it's being sent at all.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •