issue sending mail from website

Hi guys,

I am having an issue with the form on site here at http://www.detergentingredients.com/contact.html

is it maybe something to do with the process.php ?
jonathanduane2010Asked:
Who is Participating?
 
Ray PaseurCommented:
How to work with forms in PHP:
http://php.net/manual/en/tutorial.forms.php

You can use var_dump($_POST) to print out the contents of the "request" variables.  This is usually a good starting point when you're developing an application that depends on posted variables from an HTML form.
0
 
Chris StanyonCommented:
Yes - definitely - it doesn't exist !!

Submit your form and you'll get a 404 Page Not Found error /phpform/use/contact_form/process.php
0
 
jonathanduane2010Author Commented:
ok i have put one in there, but it just hangs on the page

<?php
if(isset($_POST['submit'])) {
   $to = 'jonathanduane@iradio.ie' ;     //put your email address on which you want to receive the information
   $subject = 'hello';   //set the subject of email.
   $headers  = 'MIME-Version: 1.0' . "\r\n";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   $message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>
               <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>
               <tr><td>Contact No</td><td>".$_POST['contact']."</td></tr>
               <tr><td>Message</td><td>".$_POST['message']."</td>
               </tr></table>" ;
   mail($to, $subject, $message, $headers);
   header('Location: contact.php');
}
?>

Open in new window


is this correct
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Chris StanyonCommented:
Not quite.

Your code will only get called if there is a POST key of 'submit':

if(isset($_POST['submit'])) {

There isn't one in your form. You need to give your submit button a name of 'submit':

<input type='submit' value='Submit Form' name='submit'>

Something else of note, You're creating the message using the following form fields:

name
email
contact
message

But your form actually has these fields:

Name
Email
Company
Telephone
Comments
0
 
jonathanduane2010Author Commented:
sorry, i just found that process.php online

how does this look

<?php
if(isset($_POST['submit'])) {
   $to = 'jonathanduane@iradio.ie' ;     //put your email address on which you want to receive the information
   $subject = 'hello';   //set the subject of email.
   $headers  = 'MIME-Version: 1.0' . "\r\n";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   $message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>
				<input type='submit' value='Submit Form' name='submit'> 
               <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>
               <tr><td>Company No</td><td>".$_POST['Company']."</td></tr>
               <tr><td>Telephone</td><td>".$_POST['Telephone']."</td>
			   <tr><td>Comments</td><td>".$_POST['Comments']."</td>
               </tr></table>" ;
   mail($to, $subject, $message, $headers);
   header('Location: contact.php');
}
?>

Open in new window

0
 
Ray PaseurCommented:
Is the mail() function working correctly when you isolate it and test it (without using the form)?  It returns a value that you can test for success or failure, and you would want to test this in your script and trigger an error or throw an exception if that return value indicated a failure of the function.  A good indicator does not guarantee success of the entire email process, but it would eliminate the need to consider one point of failure and that would help us move on to the next things that should be checked.

Important reading here:
http://php.net/manual/en/mail.requirements.php
http://php.net/manual/en/function.mail.php
0
 
Chris StanyonCommented:
You seem to have added the submit button in your process.php script. That's not what I meant. You need to update the submit button in your form.
0
 
jonathanduane2010Author Commented:
ok i have done that, but no change
0
 
Chris StanyonCommented:
You've now got 2 submit buttons on your form - you need one one, that includes the name attribute. Your form was fine as it was - you just needed to add name="submit" to it.

Once you've done that, add some simple logging to your PHP script. It'll help you figure out what's going on.

<?php
//Turn on error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

if(isset($_POST['submit'])) {
   $to = 'jonathanduane@iradio.ie' ;     //put your email address on which you want to receive the information
   $subject = 'hello';   //set the subject of email.
   $headers  = 'MIME-Version: 1.0' . "\r\n";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   $message = "<table><tr><td>Your Name</td><td>".$_POST['Name']."</td></tr>
               <tr><td>E-Mail</td><td>".$_POST['Email']."</td></tr>
               <tr><td>Company No</td><td>".$_POST['Company']."</td></tr>
               <tr><td>Telephone</td><td>".$_POST['Telephone']."</td>
			   <tr><td>Comments</td><td>".$_POST['Comments']."</td>
               </tr></table>" ;
   $mailsent = mail($to, $subject, $message, $headers);
   if ($mailsent) {
      header('Location: contact.php');
   }
   else
   {
      echo "The mail was not sent";
   }

} else {
   echo "No POST data was found";
}
?>

Open in new window


Once you've got that working, you'll really need to extend yout script to check that the POST array actually contains data and that the data contained is exactly what you need.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.