Results 1 to 3 of 3

Thread: [Beginner] PHP contact form trouble

  1. #1
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [Beginner] PHP contact form trouble

    i got a theme that included a contact us form, im very unfamiliar with php and was hoping someone can help me out with whats broken with it. The form validation works fine but fails in the mail sending process I have a site hosted with go daddy and did a basic php mail test page that was working fine. Here are the two files (incl_functions.js & incl_mail.php) that contain the php mail code, its a very basic contact us form. Any help would be greatly appreciated. Thanks in advance.

    incl_functions.js
    Code:
    function nl2br(text)
    {   
    	  var text = escape(text);   
    	  
    	  if(text.indexOf('%0D%0A') > -1)
    	  {   
    		var re_nlchar = /%0D%0A/g ;   
    	  }
    	  else if(text.indexOf('%0A') > -1)
    	  {
    		var re_nlchar = /%0A/g ;   
    	  }
    	  else if(text.indexOf('%0D') > -1)
    	  {   
    		var re_nlchar = /%0D/g ;   
    	  }  
    	  
    	  return unescape( text.replace(re_nlchar,'<br />'));  
    }
    
    function SendContactForm(form)
    {
    	var xmlHttp
    	
    	document.getElementById('statusbar').style.display = 'block';
    	document.getElementById('statusbar').innerHTML = 
    		'<p><strong><img src="./Images/loading.gif" alt="" width="16" /> Sending message..</strong></p>';
    	
    	form.submitcontact.disabled = true;
    	form.clear.disabled = true;
    	form.name.disabled = true;
    	form.email.disabled = true;
     	form.subject.disabled = true;
    	form.message.disabled = true;
    	
    	var name = form.name.value;
    	var email = form.email.value;
    	var subject = form.subject.value;
    	var message = nl2br(form.message.value);
    	
    	
    	
    	try
    	{  
    		//Firefox, Opera 8.0+, Safari  
    		xmlHttp=new XMLHttpRequest();
    	}
    	catch (e)
    	{  
    		// Internet Explorer  
    		try
    		{   
    			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
    		catch (e)
    		{    
    			try
    			{      
    				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
    			}
    			catch (e)
    			{      
    				alert("Your browser does not support AJAX!");      
    				return false;      
    			}    
    		}  
    	}
    	
    	xmlHttp.onreadystatechange=function()
    	{
    		if(xmlHttp.readyState==4)
    		{				
    			var response = xmlHttp.responseText;
    			var arrresponse = response.split('\\n');
    			
    			if(arrresponse[0] == 'SUCCESS') {
    				document.getElementById('formcontainer').innerHTML = '';
    			}
    			else {			
    				form.submitcontact.disabled = false;
    				form.clear.disabled = false;
    				form.name.disabled = false;
    				form.email.disabled = false;
    				form.subject.disabled = false;
    				form.message.disabled = false;
    			}
    			
    			document.getElementById('statusbar').innerHTML = '<p><strong>' + arrresponse[1] + '</strong></p>';
    	
    		}
    	}
    	
    	
    	var qstring = "./Includes/incl_mail.php?name=" + name + "&email=" + email + "&subject=" + subject + "&message=" + message;
    	
    	xmlHttp.open("GET", qstring, true);
    	xmlHttp.send(null);
    }

    incl_mail.php

    PHP Code:
    <?php

    $to 
    'contact@email.com';


    // Begin script
    if(!empty($_GET['name'])
    && !empty(
    $_GET['email'])
    && !empty(
    $_GET['message']))
    {
        
    $name $_GET['name'];;
        
    $email $_GET['email'];
        
    $subject $_GET['subject'];
        
    $message $_GET['message'];

        
    $message '    <font face="Arial, Helvetica, sans-serif" size="2">
                            ' 
    nl2br($message) . '
                            <br /><br /><br />
                        </font>
                        <font face="Arial, Helvetica, sans-serif" size="2">
                                <b>Contact:</b>
                                <br />
                        </font>
                        <font face="Arial, Helvetica, sans-serif" size="2">
                                ' 
    $name '
                                <br />
                        </font>
                        <font face="Arial, Helvetica, sans-serif" size="2">
                                ' 
    $email '
                                <br />
                        </font>'
    ;
        
        
        
    $headers "From: " $email "\n"
        
    "Reply-To: " $email "\n"
        
    "Return-Path: <" $email ">\n";
        
        
    $headers .= "MIME-Version: 1.0\n";
        
    $boundary md5(time());
        
        
    $headers .= "Content-Type: multipart/mixed; boundary = $boundary\n\n";
            
        
    $message "--$boundary\n" 
                 
    "Content-Type: text/html; charset=ISO-8859-1\n"
                 
    "Content-Transfer-Encoding: base64\n\n"
                 
    chunk_split(base64_encode($message));
                 
        
        if(
    mail($to$subject$message$headers))
        {        
            
    $status 'SUCCESS';
            
    $response 'Thank you. Your message has been successfully sent!';        
        }
        else
        {    
            
    $status 'FAILED';    
            
    $response 'Your message could not be sent. Please try again.';
        }
    }
    else
    {
        
    $status 'FAILED';    
        
    $response 'Please check these fields: ';
        
        if(empty(
    $_GET['name']))
            
    $response .= '<strong>Name</strong> | ';
        if(empty(
    $_GET['email']))
            
    $response .= '<strong>Email address</strong> | ';
        if(empty(
    $_GET['message']))
            
    $response .= '<strong>Message</strong>';
    }


    echo 
    $status '\n' $response;


    ?>
    Last edited by koleon; 08-11-2010 at 03:55 AM.

  2. #2
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    with godaddy you may have to use SMTP rather than plain PHP mail().

    Try PHPMailer

    See the links below:
    http://www.techtalkz.com/php/66199-using-phpmailer.html

    http://community.godaddy.com/groups/...script-working

  3. #3
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    but wouldnt this test page i made not work then? This successfully sends mail, which is why i think the problem is somewhere else:


    mail_test.php
    PHP Code:
    <?php

    if(mail('cbvitek@gmail.com','Colin Testing',nl2br('test message'))){

          echo(
    'ok');

        }

    else{

          echo(
    'not ok');

        }

    ?>

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
  •