Page 1 of 1

contact form not working oon new server . why ?

Posted: Tue Nov 04, 2014 11:07 am
by gautamz07
I have the following code for my PHP script for sending a mail .

Code: Select all

<?php
// check if fields passed are empty
if(empty($_POST['name'])  		||
   empty($_POST['email']) 		||
   empty($_POST['message'])	||
     empty($_POST['phone'])   ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
	echo "No arguments Provided!";
	return false;
   }
	
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
	
// create email body and send it	
$to = 'example.xxxx@gmail.com'; // put your email
$email_subject = "Contact form submitted by:  $name";
$email_body = "You have received a new message. \n\n".
				  " Here are the details:\n \nName: $name \n ".
				  "Email: $email_address\n $phone \n  Message \n $message";
$headers .= "Reply-To: $email_address";	
mail($to,$email_subject,$email_body,$headers);
return true;			
?>
when i have my html file and the php file uploaded to my bluehost server , i receive the email . Everything works fine .

but when i upload the files to my godaddy server , i mail just does't get sent . Why ??? the godaddy server is a new domain . do i need to configure something here ???

Thanks .

Re: contact form not working oon new server . why ?

Posted: Tue Nov 04, 2014 11:28 am
by Celauran
Does it not get sent or does it not get received?

Code: Select all

return true;
Not helpful. Why not return the result of the mail() call instead? Either way, you will need to look through your server's mail logs.

Re: contact form not working oon new server . why ?

Posted: Tue Nov 04, 2014 12:20 pm
by gautamz07
Celauran wrote: Not helpful. Why not return the result of the mail() call instead?
Thanks for ur quick response ? btw , how do i do that ?

also in a very general sense , is there something that i need to explicitly configure on the server .

Re: contact form not working oon new server . why ?

Posted: Tue Nov 04, 2014 12:27 pm
by gautamz07
i want it to be received btw

Re: contact form not working oon new server . why ?

Posted: Tue Nov 04, 2014 12:36 pm
by mikosiko
the first question to be answered is if you are sure that in the new host (godaddy) you have PHP available and running... one way to test is run this small script

Code: Select all

<?php
    phpinfo();
?>
if you don't get any output the PHP is not enabled/configured.... other option is no fill the input fields in your form and see if you get the error message from you php script.

Re: contact form not working oon new server . why ?

Posted: Tue Nov 04, 2014 1:29 pm
by gautamz07
so u mean @mikosiko , i jst create a index.php file and do

<?php
phpinfo();
?>

and run the url ???

Re: contact form not working oon new server . why ?

Posted: Tue Nov 04, 2014 1:42 pm
by Celauran
Yes, exactly.

Re: contact form not working oon new server . why ?

Posted: Wed Nov 05, 2014 12:23 am
by gautamz07
Hey folks , thanks for ur help i did the :

Code: Select all

<?php 
 phpinfo()
?>


thing and it showed me a whole list of php configuration and stuff . than i ran the following script :

Code: Select all

<?php
$to      = 'info@mydomainname.com'; // my address went here
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@gmail.com' . "\r\n" .
    'Reply-To: webmaster@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$mail = mail($to, $subject, $message, $headers);
echo mail($to, $subject, $message, $headers)."<br>";
if($mail){
	echo "Success";
}else{
	echo "Fail";
}
?>
and the script returned 'Fail' , which obviously means the mail was't being sent , so after that i bumbed into a little article online:

Here : http://www.problogger.net/archives/2012 ... main-name/

and well , implemented the litte steps in it . and than ran the script again :

and it returned 'Success' , and Hurreeeey !! i was receiving mails .

but i did't exactly get why wht i did worked loool .

should't the script below :

Code: Select all

<?php
$to      = 'info@mydomainname.com'; // my address went here
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@gmail.com' . "\r\n" .
    'Reply-To: webmaster@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$mail = mail($to, $subject, $message, $headers);
echo mail($to, $subject, $message, $headers)."<br>";
if($mail){
	echo "Success";
}else{
	echo "Fail";
}
?>
by itself beable to send an email ?? why is additional configuration or setup needed ???