contact form not working oon new server . why ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

contact form not working oon new server . why ?

Post 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 .
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

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

Post 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 .
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

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

Post by gautamz07 »

i want it to be received btw
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

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

Post 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.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

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

Post by gautamz07 »

so u mean @mikosiko , i jst create a index.php file and do

<?php
phpinfo();
?>

and run the url ???
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

Yes, exactly.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

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

Post 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 ???
Post Reply