Hello, I am trying to make a contact us form for a website. The form and accompanying php should work, i think. I am new to php but know how to program in general. The form and verify.php are below with some modifications for security.
contact.php snippet

<form method="post" action="verify.php" style="width: 384px">
    <table style="width: 48%; height: 121px" class="style14">
	<tr>
    	    <td colspan="2" style="height: 41px">Contact us or write customer reviews using this form:</td>
	</tr>
	<tr>
	    <td style="width: 122px; height: 40px;">
		<span class="style11">*</span>Department:</td>
	    <td style="height: 40px;">
		<select name="sendto" style="width: 240px">
		    <option value="service@****.com">Service</option>
  		    <option value="sales@****.com">Sales</option>
 		    <option value="billing@****.com">Billing</option>
		</select>
	    </td>
	</tr>
	<tr>
	    <td style="width: 122px; height: 40px;"><span class="style11">*</span>Name:</td>
	    <td style="height: 40px;">
		<input name="Name" style="width: 240px" type="text" /></td>
	</tr>
	<tr>
	    <td style="width: 122px; height: 40px;">Company:</td>
	    <td style="height: 40px;">
	        <input name="Company" style="width: 240px" type="text" /></td>
	</tr>
	<tr>
	    <td style="width: 122px; height: 40px;">
		<span class="style11">*</span>E-Mail:</td>
	    <td style="height: 40px;">
		<input name="Email" style="width: 240px" type="text" /></td>
	</tr>
	<tr>
	    <td style="width: 122px; height: 40px;">Phone:</td>
	    <td style="height: 40px;">
		<input name="Phone" style="width: 240px" type="text" />&nbsp;</td>
	</tr>
	<tr>
	    <td style="width: 122px; height: 23px;">Message:</td>
	</tr>
	<tr>
	    <td colspan="2" style="height: 169px">
	<textarea name="Message" style="width: 351px; height: 141px" class="style13">  </textarea></td>
	</tr>
	<tr>
	    <td colspan="2">
	<tr>
	    <td colspan="2" class="style10">
		<input name="send" type="submit" value="Submit" /></td>
	</tr>
	<tr>
	    <td colspan="2" class="style10">
		<span class="style11">*</span> indicates 
		required field.</td>
	</tr>
    </table>
</form>

verify.php

$to = $_POST['sendto'];
		$from = $_POST['Email'];
		$name = $_POST['Name'];
		$headers = "From: " . $from;
		$subject = "Web Contact Form";
		$message = $_POST['Message'];
		
		$fields = array();
		$fields{"Name"} = "Name";
		$fields{"Company"} = "Company";
		$fields{"Email"} = "Email";
		$fields{"Phone"} = "Phone";
		$fields{"Message"} = "Message";
		
		$body = "We Have received the following information:\n\n";
		foreach($fields as $a => $b)
			{
				$body .= sprintf("%20s: %s\n",$b,$_POST[$a]);
			} 
		
		$headers2 = "From: noreply@*****.com";
		$subject2 = "Thank you for contacting us";
		$autoreply = "some text";
		$autoreply = wordwrap($autoreply, 65);
                $send = mail($to, $subject, $body, $headers);
		$send2 = mail($from, $subject2, $autoreply, $headers2);
		if($send)
		{
		     header("Location: http://www.****.com/thankyou.html");
		}
		else
		{
			header("Location: http://www.****.com/error.html");
		}

When I test this, it keeps coming back to error.html and the emails never get sent.
Please help. It is probably something very simple i'm just too close and am overlooking it. Also for reference, the site is hosted on and being tested on GoDaddy's servers. I don't know if that makes any difference.
Thanks!

Your if statement is doing nothing. If you want to check if something is in the variable then use this:

if (isset($send))

Also, there is no part of that code where you send the mail. Lines 25 and 26 wouldn't cause the mail to send as you're just putting it into a variable.

Also, there is no part of that code where you send the mail. Lines 25 and 26 wouldn't cause the mail to send as you're just putting it into a variable.

Not true, it will send. The value returned is a boolean to show whether or not the mail was sent correctly.

Are there any log files that show why it was not sent ? Perhaps some headers are missing, but required by GoDaddy. See example #2 in the manual.

My mistake then. I always coded the page to check that the form was filled in and that the page was navigated to from the form.

@pritaeas:
There are no log files generated or I do not know where the are placed. Do you know what all is required by GoDaddy?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.