Jump to content

Recommended Posts

Hello, First of all I am NOT a PHP programmer. I am a web designer that was looking for a simple PHP contact form to add to my web site. I originally had a .NET form that I just couldn't get to look professional. I found a good form, tweaked the HTML, added the email address that I needed the form to go to, and uploaded it to my site hosted by godaddy.com. I have a Windows hosting account and it has been upgraded to IIS7, which is supposed to run PHP 5.x. The script did not work. I opened a quick free PHP site on a different host and tried it and it does work. I contacted godaddy.com and they informed me that I can use 3rd party scripts. Here is their email to me -

 

"You are not required to use our form mailers.

If you use the mail() function in your PHP, you do not need to specify an outgoing mail server. If you are using some other method besides mail() in your PHP code, use relay-hosting.secureserver.net for your relay server."

 

Here is the code that I found. I do not know PHP so I am not sure if it follows what godaddy.com is requiring for it to work.

 

<?php 
$errors = '';
$myemail = 'corifoxworthy@foxdenwebsolutions.com';
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!eregi(
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", 
$email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
$to = $myemail; 
$email_subject = "Web site form submission: $name";
$email_body = "You have received a new web site request. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message"; 

$headers = "From: $myemail"; 
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: request_response.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>

 

The HTML page links to this page. I have uploaded a phpinfo page to test and it works so PHP is installed and running. Could someone look at this code and let me know if there is anything I should add or change to get this to work on godaddy.com. Thanks.

 

 

header('Location: request_response.html');
exit();

 

You need to exit() after a header redirect.

You also might want some more headers in your email:

 

  $headers =    "MIME-Versin: 1.0\r\n" .

              "Content-type: text/plain; charset=ISO-8859-1; format=flowed\r\n" .

              "Content-Transfer-Encoding: 8bit\r\n" .

              "From: $myemail\r\n" .

                "Reply: $email_address\r\n".

              "Return-Path: $email_address\r\n".

              "X-Mailer: PHP" . phpversion();

 

Andrew - I added the code that you posted and I still am not getting an email sent to me. Now godaddy.com requires that you set up the email address that the mail is going to and I have done this using the same email in the code above. I have waited 15 minutes and no email. I checked my mail on godaddy.com just in case...not there. I pull my email through Outlook and nothing has gone to my junk email box. I have looked at several different sites and a lot of people are having problems with godaddy and emails. Maybe I should try another PHP form? I am not sure. I just want something quick and simple that visitors can fill out to request info on a web site. I do appreciate your help.

Yesterday I gave this advise to a member and they never replied:

check your php.ini file for

 

 

[mail function]

SMTP = smtp.domain.name

sendmail_from = somebody@domain.name

 

and change SMTP to

SMTP= relay-hosting.secureserver.net

 

I've noticed that no reply usually is the same thing as a thank you  :shrug:

 

http://www.phpfreaks.com/forums/index.php/topic,295526.msg1399656.html#msg1399656

I did upload the phpinfo.php file and see that these are set as follows

-

sendmail_from webmaster@secureserver.net webmaster@secureserver.net

sendmail_path no value no value

SMTP relay-hosting.secureserver.net relay-hosting.secureserver.net

 

They did tell me that if I was not using mail(); then I needed to add code for the SMTP. How do I edit the php.ini file for godaddy and what do I need to change in the code to have it go through the relay server? Sorry for being PHP ignorant.

I did upload the phpinfo.php file and see that these are set as follows

-

sendmail_from webmaster@secureserver.net webmaster@secureserver.net

sendmail_path no value no value

SMTP relay-hosting.secureserver.net relay-hosting.secureserver.net

 

They did tell me that if I was not using mail(); then I needed to add code for the SMTP. How do I edit the php.ini file for godaddy and what do I need to change in the code to have it go through the relay server? Sorry for being PHP ignorant.

 

No change is necessary, because SMTP relay-hosting.secureserver.net tells you that everything is working. This must be why they tell you that mail() doesn't need to have anything changed--php.ini has already been edited.

 

My next assumption is that this line:

if( empty($errors))

{

isn't evaluating properly.  test it by adding:

echo $errors;

before if(empty($errors))

and add

echo "sending mail";

after {

 

also put // in front of this line:

header('Location: request_response.html');

 

//header('Location: request_response.html');

 

 

and go ahead and add at the top (inside the <?php)

ini_set("display_errors", 1);

Added code as you suggested and here is the error -

 

sending mail

Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\2925570\html\foxden_site_1\contact-form-handler.php on line 39

 

I added the code you suggested above -

 


$headers =    "MIME-Versin: 1.0\r\n" . 
               "Content-type: text/plain; charset=ISO-8859-1; format=flowed\r\n" . 
               "Content-Transfer-Encoding: 8bit\r\n" . 
               "From: $myemail\r\n" . 
                "Reply: $email_address\r\n".
               "Return-Path: $email_address\r\n".
               "X-Mailer: PHP" . phpversion(); 

 

Is this the correct syntax?

 

I just tried this script and it worked but there is not enough that it picks up for what I need but I know that it works.

 

<?php

if (isset($_GET['success'])) {

?><p><span style="color:green;">Message successfully sent.</span> Thank you!</p><?php

} else {

if (!empty($_POST['email']) && !empty($_POST['message'])) {

	$to = 'corifoxworthy@foxdenwebsolutions.com'; // your email address, can be @gmail.com, etc.
	$subject = 'Contact from foxdenwebsolutions.com'; // change yoursite.com to your own domain name
	$message = $_POST['message']."\r\n\r\nSender IP: ".$_SERVER["REMOTE_ADDR"];
	$headers = 'From: '.$_POST['email']."\r\n".
				'Reply-To: '.$_POST['email']."\r\n";
	mail($to, $subject, $message, $headers);

	header("Location: request_response.html"); // redirects the sender to success page so he or she doesn't accidentally send multiple identical messages

} else {

	?><p><span style="color:red;">Error detected.</span> Please make sure you have filled all fields. Press back button to go back.</p><?php

}

}

?>

 

I am posting the form code as well so you can see what fields I need this to pick up.

 

<form method="post" name="contactform" action="contact-form-handler1.php"> 
<p align="center">
<label for='name'>Your Name:</label> <br />
<input type="text" name="name" />
</p><br />
<p align="center">
<label for='email'>Email Address:</label> <br />
<input type="text" name="email" /> 
</p><br />
<p align="center">
<label for='city'>City:</label> <br />
<input type="text" name="city" /> 
</p><br />
<p align="center">
<label for='state'>State or Province:</label> <br />
<input type="text" name="state" /> 
</p><br />
<p align="center">
<label for='country'>Country:</label> <br />
<input type="text" name="country" /> 
</p><br />
<p align="center">
<label for='message'>Web Site Request:</label> <br />
<textarea name="message" cols="40" rows="5"></textarea>
</p><br />
<p align="center">
<input type="submit" value="Submit" /><input type="reset" value="Reset" /></p><br />
<input type="hidden" name="redirect" value="request_response.html" />
</form>

 

If you just want all the data from the post put into an email:

 

<?php

if (isset($_GET['success'])) {

?><p><span style="color:green;">Message successfully sent.</span> Thank you!</p><?php

} else {

if (!empty($_POST['email']) && !empty($_POST['message'])) {

	$to = 'corifoxworthy@foxdenwebsolutions.com'; // your email address, can be @gmail.com, etc.
	$subject = 'Contact from foxdenwebsolutions.com'; // change yoursite.com to your own domain name
	//$message = $_POST['message']."\r\n\r\nSender IP: ".$_SERVER["REMOTE_ADDR"];    //this was the old message
                  $message "Email posted from IP:".$_SERVER["REMOTE_ADDR"]. "\n\n";
                 foreach ($_POST as $key => $val{
                   $message .= $key ." = ".$val."\n";
                 }
	$headers = 'From: '.$_POST['email']."\r\n".
				'Reply-To: '.$_POST['email']."\r\n";
	mail($to, $subject, $message, $headers);

	header("Location: request_response.html"); // redirects the sender to success page so he or she doesn't accidentally send multiple identical messages

} else {

	?><p><span style="color:red;">Error detected.</span> Please make sure you have filled all fields. Press back button to go back.</p><?php

}

}

?>

 

I know that this is a pretty lame representation of what you can do, but otherwise you are going to have to craft the $message variable using a combination of text and $_POST["value"](s)

 

I uploaded you code and got this error -

 

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in D:\Hosting\2925570\html\foxden_site_1\contact-form-handler1.php on line 10

 

Here is the code again.

 

<?php

if (isset($_GET['success'])){	
?><p><span style="color:green;">Message successfully sent.</span> Thank you!</p><?php
} else {

    if (!empty($_POST['email']) && !empty($_POST['message'])) {
	$to = 'corifoxworthy@foxdenwebsolutions.com'; // your email address, can be @gmail.com, etc.
	$subject = 'Contact from foxdenwebsolutions.com'; // change yoursite.com to your own domain name					//$message = $_POST['message']."\r\n\r\nSender IP: ".$_SERVER["REMOTE_ADDR"];    //this was the old message            
	$message "Email posted from IP:".$_SERVER["REMOTE_ADDR"]. "\n\n";
        	foreach ($_POST as $key => $val{ 
        	$message .= $key ." = ".$val."\n";
                 	}		
	$headers = 'From: '.$_POST['email']."\r\n".					
			'Reply-To: '.$_POST['email']."\r\n";
	mail($to, $subject, $message, $headers);		
	header("Location: request_response.html"); // redirects the sender to success page so he or she doesn't accidentally send multiple identical messages

} else {		

    ?><p><span style="color:red;">Error detected.</span> Please make sure you have filled all fields. Press back button to go back.</p>
<?php

}
}

?>

 

Line 10 is  $message "Email posted from IP:".$_SERVER["REMOTE_ADDR"]. "\n\n";

 

I have looked at some more forms but they are set up with tables. I don't want to use tables and they don't have the fields that I want.

That was the buggiest code I have every published  ;)

 

The problem is the line above where the foreach doesn't have a closing )

 

foreach ($_POST as $key => $val){ 

 

I think I should go to bed.....  maybe I just need some espresso. 

Unfortunately even though I did not get a syntax error message, no email came through. I posted it on the free PHP hosting site and it works just fine. Something is wrong on the godaddy.com side and I just can't figure out what.

 

I am messing around with the original handler that I had and am trying to learn what everything does. I don't know PHP but am willing to learn. I got all the fields to post that I want but some of them are coming back blank so I have a feeling I am not using the correct syntax.

 

<?php 
$errors = '';
$myemail = 'corifoxworthy@foxdenwebsolutions.com';
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email'];
$city = $_POST['city'];
$state = $_POST['state or province'];
$country = $_POST['country'];
$message = $_POST['web site request']; 

if (!eregi(
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", 
$email_address))
{
    $errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail; 
$email_subject = "Web site form submission: $name";
$email_body = "You have received a new web site request. ".
" Here are the details:\n Name: $name \n Email Address: $email_address \n City: $city \n State or Province: $state \n Country: $country \n Web Site Request: $message"; 

 $headers =    "MIME-Versin: 1.0\r\n" . 
               "Content-type: text/plain; charset=ISO-8859-1; format=flowed\r\n" . 
               "Content-Transfer-Encoding: 8bit\r\n" . 
               "From: $myemail\r\n" . 
                "Reply: $email_address\r\n".
               "Return-Path: $email_address\r\n".
               "X-Mailer: PHP" . phpversion(); 



mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: request_response.html');
exit();
} 
?>

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>

 

I don't know if you are parient enough with me to explain what the code is doing because I would like to learn.

Well this is interesting...I uploaded the contact form files to my clients godaddy.com site, which is a Linux account and tested the form. It works. So something is wrong on my Windows running IIS7 account. However, the fields that I played with are still not working so I need to see what I did incorrectly with the code.  ;)

Great news!!! I did some more research, copied the php.ini file from my client's site over to mine, followed a suggestion from godaddy.com to go into manage account - content - IIS management - recycle app pool and it works now. I just need to get the state or province and web site request to show up in the email using the code that I have.

You got the idea.  Good job.

 

$state = $_POST['state or province'];

should be:

$state = $_POST['state'];

 

So the $_POST is a variable (of array type--specifically associative array [which means it uses 'key' = 'value' pairs]) and each of the keys are the names of the items "post"ed (the action of the <form> tag).  So, <input type="text" name="state" /> 's value can be accessed with $_POST['state'];

 

Sorry for the buggy code, I'm glad you got it working.

I change the code for state and for message but they are still not picking up the text in the fields. Also I noticed a Javascript error on the contact form page. It says -

 

Message: 'Validator' is undefined

Line: 72

Char: 1

Code: 0

URI: http://foxden.herobo.com/contact.html

 

Line 72 is -

 

var frmvalidator  = new Validator("contactform");

 

This is the first line of the form -

 

<form method="post" name="contactform" action="contact-form-handler.php">

 

 

Well, you are going to have to post the change because from what you said, it SHOULD work.  The javascript error can be fixed by downloading:

 

http://www.javascript-coder.com/html-form/javascript_form.zip

 

putting the gen_validatorv31.js file in the same directory as your contact.html

and somewhere after <head> (but before <body>)include:

<script language="javascript" src="gen_validatorv31.js"></script>

I did get it to work and everything posted as it should have. Then suddenly I was not getting an email back again. I contacted godaddy.com and they told me I had to add my own php5.ini file? I had copied the file from my client's site to my site and that is what got it to work before but it stopped. I have no idea how to write a php.ini file to get the code to work.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.