Page 1 of 1

PHP Mailer Script not working. Need some help

Posted: Sun Dec 03, 2006 8:03 am
by warrendistler
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I was asked to host an existing web site that was written in PHP. The only scripting element in the web site is a form mailer. When I originally transfered the site to my server it was working. Now, for some reason, it does not work any more. I am trying to avoid having to transform the web site from PHP to ASP. Any help or suggestions on the script and/or potential causes fro my problem would be appreciated.

Code: Select all

<form action="/contact/index.php" method="post">
									<font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?

extract($_POST);

if(isset($send_form)) {

	$empty_fields="";

	$errors=0;

	// empty field checking

	function valid_email($email) {

		if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)){

			return true;

		}else{

			return false;

		}

	}



	if ($Name == ""){

		$errors++;

		$empty_fields[] .= "Name";

	}



	// email Validation

	if (valid_email($email)==false) {

		$errors++;

		print "<p>Please enter a valid email so that you'll be able to be reached quickly</p>\n";

	}

	if ($errors == 0) {

		// Sends e-mail 

		$recipient .= "name@website.com";

		$subject = "Around the Clock Care Web Form Submission";

		

		$message .=  "Name: ".$Name."\n"."Address: ".$Address."\n"."City: ".$City."\n"."State: ".$State."\n"."Zip: ".$Zip."\n"."Phone: ".$Phone."\n"."Fax: ".$Fax."\n"."Email: ".$email."\n"."Contact me by: ".$Contactmeby."\n";

		
  
		//if($fax != "") { $message .= "Fax: ".$fax."\n"; }

		 

		if($website != "") { $message .= "Website: ".$website."\n"; }

		

		if($p_o_number != "") { $message .= "Purchase Order no. ".$p_o_number."\n"; }

		

		if($parts != "") { 

			$message .= "\nParts requested:\n";

			for($i=0; $i<count($parts); $i++) {

				if($parts[$i] != "") { $message .= $quantity[$i]."\t".$parts[$i]."\n"; }

			}

		}

		if($comment != "") { $message .= "\n: ".$comment."\n"; }

		$headers .= "From: ".$email."";

		mail($recipient, $subject, $message, $headers) OR $send_error="on";

		if(isset($send_errors)) {

			print "<p>Couldn't send e-mail.  Please <a href="#" onClick="history.go(-1)">go back</a> on your browser, and try again.\n";

		}

		else {

			// Print Thank You Page 

		
/* This will give an error. Note the output
Ê* above, which is before the header() call */
print "<h2>Thank You!</h2>\n\n";
			print "<p>Your request has processed successfully.</p>\n\n";
			print "<p>We will contact you by the method you requested as soon as possible.</p>\n\n";

		}

	}

	else {

		print "<p>We are missing some information. Please <a href="#" onClick="history.go(-1)">go back</a> and fill in the following fields:</p>\n\n<ul>\n";

		while($each_error = each($empty_fields)) {

			print "\t<li>".$each_error[value]."</li>\n";

		}

		print "</ul>\n";

	}

}

else { ?></font>
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td width="75"><span class="smalldark"><br>
												</span><span class="small">Name:</span></td>
											<td width="11"></td>
											<td width="50%"><br>
												<input type="text" name="Name" size="15"></td>
											<td width="75"><br>
												<span class="small">Email:</span></td>
											<td width="11"></td>
											<td width="50%"><br>
												<input type="text" size="15" name="email"></td>
										</tr>
										<tr>
											<td width="75"><br>
												<span class="small">Address:</span></td>
											<td width="11"></td>
											<td width="50%"><br>
												<input type="text" name="Address" size="15"></td>
											<td width="75"><br>
												<span class="small">City:</span></td>
											<td width="11"></td>
											<td width="50%"><br>
												<input type="text" name="City" size="15"></td>
										</tr>
										<tr>
											<td width="75"><br>
												<span class="small">State:</span></td>
											<td width="11"></td>
											<td width="50%"><br>
												<input type="text" name="State" size="15"></td>
											<td><br>
												<span class="small">Zip:</span></td>
											<td></td>
											<td width="50%"><br>
												<input type="text" name="Zip" size="8" maxlength="5"></td>
										</tr>
										<tr>
											<td width="75"><br>
												<span class="small">Phone:</span></td>
											<td width="11"></td>
											<td width="50%"><br>
												<input type="text" name="Phone" size="15"></td>
											<td></td>
											<td></td>
											<td width="50%"></td>
										</tr>
									</table>
									<br>
									<b><span class="small">Please enter comments or questions below:<br>
										</span><span class="small"><br>
											<textarea name="Comments" rows="3" cols="50"></textarea><br>
											<br>
										</span></b>
									<table width="311" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td nowrap width="178"><b><span class="small">Preferred method of contact:</span></b></td>
											<td width="11"><img src="../blank.gif" alt="" height="11" width="1" border="0" hspace="5"></td>
											<td width="122"><select name="Contactmeby" size="1" class="small">
													<option value="Email">Email</option>
													<option value="Phone">Phone</option>
												</select></td>
										</tr>
									</table>
									<br>
									<font face=verdana size=3><input name="submit" type="submit"  value="Submit">
                </font><font face=verdana size=3> </font><font face=verdana size=3><input type='hidden' name="send_form" value="true">
                </font>
								</form>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]1.[/b] Select the correct board for your query. Take some time to read the guidelines in the sticky topic.[/quote]

Posted: Sun Dec 03, 2006 8:20 am
by ok
Where the error appears? when you send an email?

I advice you using Swift Mailer or if you want PHPMailer.

PHP Mailer Problem

Posted: Sun Dec 03, 2006 4:44 pm
by warrendistler
It doesn't throw an error message. Everything from the web site end looks good. I get a confirmation that the form has been submitted. The e-mail just never arrives at the intended address.

Re: PHP Mailer Problem

Posted: Sun Dec 03, 2006 5:10 pm
by ok
warrendistler wrote:

Code: Select all

$headers .= "From: ".$email."";
mail($recipient, $subject, $message, $headers) OR $send_error="on";
If you use $var.=x; you have to set the $var before, otherwise it can contain some garbage ("0"...).

Code: Select all

$headers = "From: ".$email."";
mail($recipient, $subject, $message, $headers) OR $send_error="on";
The same with "$recipient".