Jump to content

PHP upgrade problem - script no longer works :(


simonp

Recommended Posts

Hello,

 

We have a simple contact form written in PHP that worked fine until our server was upgraded to PHP Version 4.4.6 - now it doesn't send the mail.

 

Is there a way to find out why not? I know you can force errors to the browser in CGI Perl - can I do anything in PHP?

 

Hope someone can help!

 

Simon

Link to comment
Share on other sites

Hi,

 

Sorry - here's the code:

 


<?php
// only validate form when form is submitted

$sucess = 'no';

if(isset($submit_button)){
$error_msg='';
if($contactName=='') {
	$error_msg.="<li>Please tell us your name!</li>";
}


	if($contactEnquiry=='') {
	$error_msg.="<li>You didn't enter a message!</li>";
}



// display error message if any, if not, proceed to other processing
if($error_msg==''){

	// Everything seems cool so let us do what we do

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

	//Delivery info
$deliverto='EMAILADDRESS REMOVED';
$subject='customer enquiry';
$mailcontent = "customer enquiry\n\n"
							 .'Name:       '.$contactName."\n"
						 	 .'E-mail:     '.$contactEmail."\n"
							 .'Telephone:  '.$contactTelephone."\n"
							 .'Domain:     '.$contactDomain."\n"
							 .'Ringback:   '.$contactRingback."\n"
							 .'Enquiry:    '.$contactEnquiry."\n\n"
							 .'IP address: '. $_SERVER["REMOTE_ADDR"]."\n"
							 .'Hostname:   ' . $hostname;
$from = "From: $contactName <$contactEmail>\r\n";

mail($deliverto, $subject, $mailcontent, $from);	

?>

 

Link to comment
Share on other sites

Looking at the code I would say the error is somewhere in the contents of the $mailcontent variable as everything else looks fine. Experiment with sending a very basic email like one piece of text and see what happens. Progressively add more data and see when it fails.

 

I'd also advise to add some sort of basic error checking with the mail() function like this:

if (mail($deliverto, $subject, $mailcontent, $from)) {
  echo 'Mail sent OK';
} else {
  echo 'Mail sending failed';
}

Link to comment
Share on other sites

humm - seems like it might not be the mail code after all - it doesn't look like it's even passing the variables from the form.

 

This is the code on the form. Can anyone see what might be wrong?:

 

<form method="post" name="contactform" action="submission.php" style="margin: 0px; padding: 0px;">
<table border="0" class="contactTable noprint">

<tr>
<td colspan="2">Leave your details here and we'll get back to you by e-mail or phone.</td>
</tr>
<tr>
  <td>
  <label for="contactName"><b>Your name:</b></label>
  </td>
  <td>
  <input type="formText" name="contactName"  value="<?php echo $contactName; ?>">
  </td>
</tr>

<tr>
  <td>
  <label for="contactEmail"><b>Your e-mail address:</b></label>
  </td>
  <td>
  <input type="text" name="contactEmail" value="<?php echo $contactEmail; ?>">
  </td>
</tr>

<tr>
  <td>
  <label for="contactTelephone"><b>Your telephone number:</b></label>
  </td>
  <td>
  <input type="text" name="contactTelephone"  value="<?php echo $contactTelephone; ?>">
  </td>
</tr>

<tr>
  <td>
  <label for="contactDomain"><b>Your domain name</b> (if applicable):</label>
  </td>
  <td>
  <input type="text" name="contactDomain"  size="27" value="<?php echo $contactDomain; ?>">
  </td>
</tr>

<tr>
  <td valign="top">
  <label for="contactEnquiry" valign="top"><b>Your enquiry:</b></label>
  </td>
  <td>
  <textarea rows="6" name="contactEnquiry" style="width: 200px;"><?php echo $contactEnquiry; ?></textarea>
  </td>
</tr>

<tr>
  <td valign="top">
  <label for="contactRingback" valign="top"><b>I'd like you to call me back:</b></label>
  </td>
  <td>
<select name="contactRingback">
  <option value="No ringback required" selected>I don't require a ringback</option>
  <option value="Call as soon as possible">As soon as possible</option>
  <option value="Call sometime today">Sometime today</option>
  <option value="Call tomorrow">Tomorrow</option>
</select>
  </td>
</tr>

<tr>
  <td>
  
  </td>
  <td>
  <input type="submit" value="Send your enquiry" name="submit_button" id="submit_button">
  </td>
</tr>

</table>
</form>

 

 

 

. . . .and this is the submission.php

 

 

 


<?php
// only validate form when form is submitted

$sucess = 'no';

if(isset($submit_button)){
$error_msg='';
if($contactName=='') {
	$error_msg.="<li>Please tell us your name!</li>";
}


	if($contactEnquiry=='') {
	$error_msg.="<li>You didn't enter a message!</li>";
}


// display error message if any, if not, proceed to other processing
if($error_msg==''){

	// Everything seems cool so let us do what we do

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

	//Delivery info
$deliverto='EMAIL ADDRESS REMOVED';
$subject='customer enquiry';
$mailcontent = "customer enquiry\n\n"
							 .'Name:       '.$contactName."\n"
						 	 .'E-mail:     '.$contactEmail."\n"
							 .'Telephone:  '.$contactTelephone."\n"
							 .'Domain:     '.$contactDomain."\n"
							 .'Ringback:   '.$contactRingback."\n"
							 .'Enquiry:    '.$contactEnquiry."\n\n"
							 .'IP address: '. $_SERVER["REMOTE_ADDR"]."\n"
							 .'Hostname:   ' . $hostname;
$from = "From: $contactName <$contactEmail>\r\n";

mail($deliverto, $subject, $mailcontent, $from);	



//if (mail($deliverto, $subject, $mailcontent, $from)) {
//  echo 'Mail sent OK';
//} else {
//  echo 'Mail sending failed';
//}


?>

<p>Thanks for your enquiry. We'll get back to you as soon as possible.</p>

<?php

echo "<table class=\"contactConfirm\" border=\"0\">";
echo "<tr><td colspan=\"2\" class=\"contactConfirmX\"> here's what you submitted:</td></tr>";
if ($contactName !== '') {
echo "
<tr>
<td valign=\"top\" class=\"contactConfirmY\">Name:</td><td valign=\"top\">$contactName</td>
</tr>";
}

if ($contactEmail !== '') {
echo "
<tr>
<td valign=\"top\" class=\"contactConfirmY\">E-mail:</td><td valign=\"top\">$contactEmail</td>
</tr> ";
}

if ($contactTelephone !== '') {
echo "
<tr>
<td valign=\"top\" class=\"contactConfirmY\">Telephone:</td><td valign=\"top\">$contactTelephone</td>
</tr>"; 
}

if ($contactDomain !== '') {
echo "
<tr>
<td valign=\"top\" class=\"contactConfirmY\">Domain:</td><td valign=\"top\">$contactDomain</td>
</tr>";
}

echo "
<tr>
<td valign=\"top\" class=\"contactConfirmY\">Ringback:</td><td valign=\"top\">$contactRingback</td>
</tr>";





if ($contactEnquiry !== '') {
echo "
<tr>
<td valign=\"top\" class=\"contactConfirmY\">Enquiry:</td><td valign=\"top\">$contactEnquiry</td>
</tr>

"; }
echo "</table>";

	echo "</tr></td>";

$sucess = 'yes';


} else {
echo "<tr><td colspan=\"2\">";
	echo "<p>Sorry, there was an error with your submission. Take a look at the problems listed below and try again.</p>";
	echo "<ul class=\"formError\">$error_msg</ul>";
	echo "</tr></td>";
}
}
?>

<?php if($sucess=='no'){ ?>

<?php

echo $sucess;

?>

<div class="contactTitle"><img src="contactform.gif" alt="Contact form" border="0"></div>

<form method="post" name="contactform" action="submission.php" style="margin: 0px; padding: 0px;">
<table border="0" class="contactTable">

<tr>
<td colspan="2">Leave your details here and we'll get back to you by e-mail or phone.</td>
</tr>
<tr>
  <td>
  <label for="contactName"><b>Your name:</b></label>
  </td>
  <td>
  <input type="formText" name="contactName"  value="<?php echo $contactName; ?>">
  </td>
</tr>

<tr>
  <td>
  <label for="contactEmail"><b>Your e-mail address:</b></label>
  </td>
  <td>
  <input type="text" name="contactEmail" value="<?php echo $contactEmail; ?>">
  </td>
</tr>

<tr>
  <td>
  <label for="contactTelephone"><b>Your telephone number:</b></label>
  </td>
  <td>
  <input type="text" name="contactTelephone"  value="<?php echo $contactTelephone; ?>">
  </td>
</tr>

<tr>
  <td>
  <label for="contactDomain"><b>Your domain name</b> (if applicable):</label>
  </td>
  <td>
  <input type="text" name="contactDomain"  size="27" value="<?php echo $contactDomain; ?>">
  </td>
</tr>

<tr>
  <td valign="top">
  <label for="contactEnquiry" valign="top"><b>Your enquiry:</b></label>
  </td>
  <td>
  <textarea rows="6" name="contactEnquiry" cols="20"><?php echo $contactEnquiry; ?></textarea>
  </td>
</tr>

<tr>
  <td valign="top">
  <label for="contactRingback" valign="top"><b>I'd like you to call me back:</b></label>
  </td>
  <td>
<select name="contactRingback">
  <option value="No ringback required" selected>I don't require a ringback</option>
  <option value="Call as soon as possible">As soon as possible</option>
  <option value="Call sometime today">Sometime today</option>
  <option value="Call tomorrow">Tomorrow</option>
</select>
  </td>
</tr>

<tr>
  <td>
  
  </td>
  <td>
  <input type="submit" value="Send your enquiry" name="submit_button" id="submit_button">
  </td>
</tr>




</table>
</form>
<?php }; ?>

 

Link to comment
Share on other sites

I've actually remed all that out which is how I found out nothing is being passed from the form :(

 

//if(isset($submit_button)){
//	$error_msg='';
//	if($contactName=='') {
//		$error_msg.="<li>Please tell us your name!</li>";
//	}
//
//
//		if($contactEnquiry=='') {
//		$error_msg.="<li>You didn't enter a message!</li>";
//	}

// display error message if any, if not, proceed to other processing
//	if($error_msg==''){

Link to comment
Share on other sites

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.