Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2013, 09:02 AM   PM User | #1
frickettz
New Coder

 
Join Date: Jun 2012
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
frickettz is an unknown quantity at this point
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); 
frickettz is offline   Reply With Quote
Old 01-09-2013, 09:47 AM   PM User | #2
frickettz
New Coder

 
Join Date: Jun 2012
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
frickettz is an unknown quantity at this point
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>
frickettz is offline   Reply With Quote
Old 01-09-2013, 10:37 AM   PM User | #3
Thyrosis
New Coder

 
Join Date: Nov 2012
Posts: 72
Thanks: 4
Thanked 11 Times in 11 Posts
Thyrosis is on a distinguished road
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.
Thyrosis is offline   Reply With Quote
Reply

Bookmarks

Tags
contact form, php mail function

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:13 AM.


Advertisement
Log in to turn off these ads.