Jump to content

*Sigh* Issues with mail()


virtualscouser

Recommended Posts

I have a form that I created for one of my clients that works peachy. I copied and pasted all the code from the form (along with the PHP) and did some modifications to it for another client.(why mess with a good thing right?) When I click the submit button no email is sent. I get the "Thanks for submitting your information" page and when I leave out the required fields, PHP does it's job and tells me that I'm missing them. The hosting company uploaded a phpmail file and that works fine.(sends the email no problem) So I' really lost why this form isn't working.

 

Here's the code:

 

<?php if (isset($_POST['submit'])) { // handle the form.

 

//Check for first name.

if (strlen($_POST['first_name']) > 0) {

$first_name = TRUE;

} else {

$first_name = FALSE;

echo '<p>You forgot to enter your first name!</p>';

}

//Check for last name.

if (strlen($_POST['last_name']) > 0) {

$last_name = TRUE;

} else {

$last_name = FALSE;

echo '<p>You forgot to enter your last name!</p>';

}

//Check for email.

if (strlen($_POST['email']) > 0) {

$email = TRUE;

} else {

$email = FALSE;

echo '<p>You forgot to enter your e-mail address!</p>';

}

 

if ($first_name && $last_name && $email) { //If everything's ok.

// Good to go.

 

$to = "My Email goes here";

$subject = "Information Request";

$message .= "First Name:\t".$_REQUEST["first_name"]."\n";

$message .= "Last Name:\t".$_REQUEST["last_name"]."\n";

$message .= "Phone Number:\t".$_REQUEST["phone"]."\n";

$message .= "Email:\t".$_REQUEST["email"]."\n";

$message .= "How did you find us?:\t".$_REQUEST["refered"]."\n";

$message .= "Comments:\t".$_REQUEST["comments"]."\n";

$from = "$email";

 

$headers = "From: $from";

 

mail($to,$subject,$message,$headers);

 

echo '<p>Thanks for your interest. If requested, we will contact you using your provided information.</p>';

} else { // not ok.

echo '<p>Please go back and insert the required information.</p>';

}

 

} else { // Display the form.

?>

            <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

<table width="500" border="0" align="center" cellpadding="5" cellspacing="0">

      <tr>

            <td colspan="2"><div align="left"><span class="style8b">Enter your information in the form below:</span></div></td>

      </tr>

<tr>

<td width="150"><span class="style5"><span class="style17">*</span>First Name:</span></td>

<td width="300"><input name="first_name" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5"><span class="style17">*</span>Last Name:</span></td>

<td><input name="last_name" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5">Phone Number :</span></td>

<td><input name="phone" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5">*Email:</span></td>

<td><input name="email" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5">How did you find us?:</span></td>

<td><input name="refered" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5">Comments:</span></td>

<td><textarea name="comments" cols="40" rows="3"></textarea></td>

</tr>

<tr>

                    <td> </td>

                    <td> </td>

            </tr>

<tr>

<td colspan="2"><div align="center"><input name="submit" type="submit" class="style5" value="Submit" /></div></td>

</tr>

</table>

</form>

<!-- End of the form -->

<?php } ?></p>

Link to comment
https://forums.phpfreaks.com/topic/135690-sigh-issues-with-mail/
Share on other sites

check what error you're getting, see if it thinks its sending

 

if(mail($to,$subject,$message,$headers)) echo 'all good';
else echo 'not sent';

 

That's the thing, I'm not getting any errors, it comes back with the message thanking me for submitting my information like everything is fine. I just never receive the email.

The way your code is laid out, you're not checking if the mail() function returns true.

 

Put my little bit of code in place of yours and let me know what it says

 

change;

 

mail($to,$subject,$message,$headers);

      echo '<p>Thanks for your interest. If requested, we will contact you using your provided information.</p>';

 

to

 

if(mail($to,$subject,$message,$headers)) echo 'all good';
else echo 'not sent';

Nope, your code crashes the page. Gives me a HTTP500 error when submit is clicked.

 

The way your code is laid out, you're not checking if the mail() function returns true.

 

Put my little bit of code in place of yours and let me know what it says

 

change;

 

mail($to,$subject,$message,$headers);

      echo '<p>Thanks for your interest. If requested, we will contact you using your provided information.</p>';

 

to

 

if(mail($to,$subject,$message,$headers)) echo 'all good';
else echo 'not sent';

Post your code, with mine in place

 

<?php if (isset($_POST['submit'])) { // handle the form.

 

//Check for first name.

if (strlen($_POST['first_name']) > 0) {

$first_name = TRUE;

} else {

$first_name = FALSE;

echo '<p>You forgot to enter your first name!</p>';

}

//Check for last name.

if (strlen($_POST['last_name']) > 0) {

$last_name = TRUE;

} else {

$last_name = FALSE;

echo '<p>You forgot to enter your last name!</p>';

}

//Check for email.

if (strlen($_POST['email']) > 0) {

$email = TRUE;

} else {

$email = FALSE;

echo '<p>You forgot to enter your e-mail address!</p>';

}

 

if ($first_name && $last_name && $email) { //If everything's ok.

// Good to go.

 

$to = "MyEmail Here";

$subject = "Information Request";

$message .= "First Name:\t".$_REQUEST["first_name"]."\n";

$message .= "Last Name:\t".$_REQUEST["last_name"]."\n";

$message .= "Phone Number:\t".$_REQUEST["phone"]."\n";

$message .= "Email:\t".$_REQUEST["email"]."\n";

$message .= "How did you find us?:\t".$_REQUEST["refered"]."\n";

$message .= "Comments:\t".$_REQUEST["comments"]."\n";

$from = "$email";

 

$headers = "From: $from";

 

 

if(mail($to,$subject,$message,$headers)) echo 'all good';

else echo 'not sent';

 

} else { // Display the form.

?>

            <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

<table width="500" border="0" align="center" cellpadding="5" cellspacing="0">

<tr>

<td colspan="2"><div align="left"><span class="style8b">Enter your information in the form below:</span></div></td>

</tr>

<tr>

<td width="150"><span class="style5"><span class="style17">*</span>First Name:</span></td>

  <td width="300"><input name="first_name" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5"><span class="style17">*</span>Last Name:</span></td>

<td><input name="last_name" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5">Phone Number :</span></td>

<td><input name="phone" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5">*Email:</span></td>

<td><input name="email" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5">How did you find us?:</span></td>

<td><input name="refered" type="text" size="40" /></td>

</tr>

<tr>

<td><span class="style5">Comments:</span></td>

<td><textarea name="comments" cols="40" rows="3"></textarea></td>

</tr>

<tr>

                    <td> </td>

                    <td> </td>

                </tr>

<tr>

<td colspan="2"><div align="center"><input name="submit" type="submit" class="style5" value="Submit" /></div></td>

</tr>

</table>

  </form>

<!-- End of the form -->

<?php } ?>

Try this, and don't forget to put your email address in ;)

 

<?php if (isset($_POST['submit'])) { // handle the form.

//Check for first name.
      if (strlen($_POST['first_name']) > 0) {
         $first_name = TRUE;
      } else {
         $first_name = FALSE;
         echo '<p>You forgot to enter your first name!</p>';
      }
//Check for last name.
      if (strlen($_POST['last_name']) > 0) {
         $last_name = TRUE;
      } else {
         $last_name = FALSE;
         echo '<p>You forgot to enter your last name!</p>';
      }
//Check for email.
      if (strlen($_POST['email']) > 0) {
         $email = TRUE;
      } else {
         $email = FALSE;
         echo '<p>You forgot to enter your e-mail address!</p>';
      }

   if ($first_name && $last_name && $email) { //If everything's ok.
      // Good to go.
      
      $to = "MyEmail Here";
      $subject = "Information Request";      
      $message = "First Name:\t".$_REQUEST['first_name']."\n";
      $message .= "Last Name:\t".$_REQUEST['last_name']."\n";
      $message .= "Phone Number:\t".$_REQUEST['phone']."\n";
      $message .= "Email:\t".$_REQUEST['email']."\n";
      $message .= "How did you find us?:\t".$_REQUEST['refered']."\n";
      $message .= "Comments:\t".$_REQUEST['comments']."\n";
      $from = "$email";
      
      $headers = "From: $from";
      
      
      if(mail($to,$subject,$message,$headers)) echo 'all good';
      else echo 'not sent';

} else { // Display the form.
?>
            <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
                     <table width="500" border="0" align="center" cellpadding="5" cellspacing="0">
                        <tr>
                           <td colspan="2"><div align="left"><span class="style8b">Enter your information in the form below:</span></div></td>
                        </tr>
                        <tr>
                           <td width="150"><span class="style5"><span class="style17">*</span>First Name:</span></td>
                          <td width="300"><input name="first_name" type="text" size="40" /></td>
                        </tr>
                        <tr>
                           <td><span class="style5"><span class="style17">*</span>Last Name:</span></td>
                           <td><input name="last_name" type="text" size="40" /></td>
                        </tr>
                        <tr>
                           <td><span class="style5">Phone Number :</span></td>
                           <td><input name="phone" type="text" size="40" /></td>
                        </tr>
                        <tr>
                           <td><span class="style5">*Email:</span></td>
                           <td><input name="email" type="text" size="40" /></td>
                        </tr>
                        <tr>
                           <td><span class="style5">How did you find us?:</span></td>
                           <td><input name="refered" type="text" size="40" /></td>
                        </tr>
                        <tr>
                           <td><span class="style5">Comments:</span></td>
                           <td><textarea name="comments" cols="40" rows="3"></textarea></td>
                        </tr>
                        <tr>
                                <td> </td>
                                <td> </td>
                            </tr>
                        <tr>
                           <td colspan="2"><div align="center"><input name="submit" type="submit" class="style5" value="Submit" /></div></td>
                        </tr>
            </table>
           </form>            
            <!-- End of the form -->
<?php } ?>

Anybody else want to take a stab at this? What is really winding me up about it is that the hosting company sent me a simple php program that works just fine, I receive the sample mail it sends without issue so I know the server is sending the mail but for some reason it doesn't want to process my script. ??? The validation works but it just won't send the email. Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.