Forum Moderators: coopster

Message Too Old, No Replies

Form submits, no email arrives

form submits, no error messages, form doesn't arrive in email inbox

         

MikeSA1965

4:59 am on Mar 29, 2010 (gmt 0)

10+ Year Member



I have an enquiry form on my work website. I can fill in the boxes, and hit submit, the page redirects and says the message is sent, but nothing arrives in the inbox.
My form is written in html, and submitted through the php page.

This is my php.

[size=2]
<?php
$emailaddress = 'tenders@example.com';
$fromaddress = 'enquiryform@example.com';


$retvalue = 'Error';

if($_POST['submit'] === 'submit') {
$retvalue = 'Enquiry form submitted';

$messagebody .= '<br>';
$messagebody = '<b>Enquirey Form</b>';

$messagebody .= '<br>';
$messagebody .= '<b>Submitted:</b>' . '&nbsp;' . date("F j, Y, g:i a");
$messagebody .= '<br>';
$messagebody .= '<br>';

// Details
$messagebody .= '<br>';
$messagebody .= '<b>Company Details:</b>';
$messagebody .= '<br>';
$messagebody .= 'Company:' . '&nbsp;' . getvalue('company');
$messagebody .= '<br>';
$messagebody .= 'Name:' . '&nbsp;' . getvalue('name');
$messagebody .= '<br>';
$messagebody .= 'Address:' . '&nbsp;' . getvalue('address');
$messagebody .= '<br>';
$messagebody .= 'City:' . '&nbsp;' . getvalue('city');
$messagebody .= '<br>';
$messagebody .= 'State:' . '&nbsp;' . getvalue('state');
$messagebody .= '<br>';
$messagebody .= 'Postcode:' . '&nbsp;' . getvalue('postcode');
$messagebody .= '<br>';
$messagebody .= '<br>';
$messagebody .= '<b>Contact Details:</b>';
$messagebody .= '<br>';
$messagebody .= 'Phone:' . '&nbsp;' . getvalue('phone');
$messagebody .= '<br>';
$messagebody .= 'Mobile:' . '&nbsp;' . getvalue('mobile');
$messagebody .= '<br>';
$messagebody .= 'Email:' . '&nbsp;' . getvalue('email');
$messagebody .= '<br>';
$messagebody .= '<br>';
$messagebody .= '<b>Job Type</b>';
$messagebody .= '<br>';
$messagebody .= getcheck('Designs', 'design');
$messagebody .= getcheck('Extensions', 'extensions');
$messagebody .= getcheck('Interior', 'interior');
$messagebody .= getcheck('New Home', 'newhome');
$messagebody .= getcheck('Rammed Earth', 'rammedearth');
$messagebody .= getcheck('Renovations', 'renovations');
$messagebody .= getcheck('Commercial', 'commercial');
$messagebody .= '<br>';
$messagebody .= '<b>Additional Job Details:</b>';
$messagebody .= '<br>';
$messagebody .= getvalue('jobdetails');
$messagebody .= '<br>';

// Email Layout
$message = '<html><head><title>Enquirey form</title></head><body>';
$message .= $messagebody;
$message .= '</body></html>';


// Send the mail
$to = $emailaddress;
$subject = 'Enquirey form submitted ' . date("F j, Y, g:i a");
$message = $message;
$headers = 'MIME-Version: 1.0' . "\n.";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n.";
$headers .= 'Content-Transfer-Encoding: 7bit'."\n.";
$headers .= 'From: ' . $fromaddress . "\n." .
'Reply-To: ' . $fromaddress . "\n." .
'X-Mailer: PHP/' . phpversion();

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

// Quote Submitted
$retvalue = 'Thank you for your time - please wait to be redirected to our homepage';//Message printed once form has been submitted


}


function getcheck($name, $check) {


if(isset($_POST[$check]))
$text .= '[x]';
else
$text .= '[&nbsp;&nbsp;]';

$text .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $name;

$text .= '<br>';
return $text;
}

function getvalue($check) {
$text = '';

if(isset($_POST[$check])) {
$text = $_POST[$check];
}

return $text;
}
?>
[/size]



Any suggestions?
What am I missing?

Many Thanks
Mike

[edited by: dreamcatcher at 7:16 am (utc) on Mar 29, 2010]
[edit reason] Exemplified Email Addresses [/edit]

Matthew1980

7:15 am on Mar 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there MikeSA1965,

Welcome to the forum ;-p

firstly
Check to see if the value is set:-

if (isset($_POST['submit']) && ($_POST['submit'] == "submit")){
//handle if true

Secondly

Construction of the page: You are building a var, $messagebody using the .= operator, and there is a $messagebody that only has = assigned to it:-

$messagebody .= '<b>Enquirey Form</b>'; //add the . so the string can be built ;p

Thirdly

Again the .= havn't been implemented correctly, and the ; are missing from the end of statement. I have tried to format it but you should be able to see what I was aiming at with what I have done. ;-p

// Send the mail
$to = $emailaddress;
$subject = 'Enquirey form submitted ' . date("F j, Y, g:i a");

//Change this var too as you are assigning the same thing to itself ;-p
$Newmessage = $message;

$headers = 'MIME-Version: 1.0' . '\n.';
$headers .= 'Content-type: text/html; charset=iso-8859-1' .'\n.';
$headers .= 'Content-Transfer-Encoding: 7bit'.'\n.';
$headers .= 'From: ' . $fromaddress . '\n.';
$headers .= 'Reply-To: '.$fromaddress.'\n.';
$headers .= 'X-Mailer: PHP/'.phpversion();

Fourthly
I'm not sure why you are building two sets of vars to house the html message, why not just stick to one var, it's easier to handle then, and then you can put the headers at the top so that the code reads more fluidly.

I'm not sure what the last custom functions are doing, but for the moment, I'll stick to the mail being sent ;-p

Try that first off,

Cheers,
MRb

MikeSA1965

10:22 pm on Mar 29, 2010 (gmt 0)

10+ Year Member



Thanks Matthew,
I own up to not writing the php, just having to try and fix it. What I have been trying is to 'comment' out everything and starting with 1 bit at a time find what works. I shall take your fine suggestions on board and work through a solution.
Thanks for your ideas.
Mike

MikeSA1965

2:27 am on Mar 30, 2010 (gmt 0)

10+ Year Member



Update;
When my form submits, I have used the $_POST[] and an echo to print all the form data on the page the form redirects to. This information is being collected and printed. The 'wording' of the email bits, the 'to' 'from'etc are as www.w3c.schools suggest in their email, as do numerous other people in various posts. Could the problem be server side?

Matthew1980

7:26 am on Mar 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there MikeSA1965,

Firstly:-

When using a form & it's elements to populate an email & it's contents, before you even check that the email is being constructed, check that the $_POST var's are getting sent from the form into the function/file that you have to that is using the data.

A good method to check that the form has actually sent data is simply to use the print_r($_POST); function on the function/file that the data is getting sent to (hope that makes sense ;-p).

Once your sure that the relevant data is getting sent, you can then either assign each key to a var or echo the $_POST key direct, that your choice :)

Email html construction:-

$message = '<html>\n\r';
$message .= '<head>\n\r';
$message .= '<title>Enquiry form</title>\n\r';
$message .= '</head>\n\r';
$message .= '<body>\n\r';
$message .= 'Name:'.strip_tags($_POST['name']).'\n\r';
$message .= 'Email:'.strip_tags($_POST['email']).'\n\r';
$message .= 'Comments:'.strip_tags($_POST['comments']).'\n\r';
$message .= '</body></html>'\n\r';

NOTE: I have used the strip_tags function as a method of prevention of malicious code injection, always protect the code you write :)


Use the above as a way to construct the html, then instead of two vars being joined, you will only need the one, and don't forget that doing the format in echo's you will need the new line & carriage return to help with keeping everything on one line ;)

I'm not sure what you are trying to do with the 'getcheck' function, but firstly I suggest bypassing that, and ensuring that the vars are passed from the form to the email script.

Don't forget that if you are attempting to pass $_POST into a function, there is no need to place it in the function as a parameter, as by definition it is a super global therefore the array is accessible anywhere in the script once the form is submitted. I just thought I would make you aware of this.

Let's just get the email going first ;-p

[EDIT]: Check the spam filter once you have the email sending, as sometimes they end up in the spam box

Cheers,
MRb

MikeSA1965

10:37 pm on Mar 30, 2010 (gmt 0)

10+ Year Member



Many Thanks Matthew,
Again I DID NOT write this code, I have come along at the request of my boss and am trying to fix it. Your help is MUCH appreciated. I will try and add your suggestions.
I did comment out all the code except for the mail sending piece,

// Send the mail



$to = 'tenders@example.com.au';

$subject = 'Enquiry form submitted ' . date("F j, Y, g:i a");

$Newmessage = $message;

$fromaddress = 'enquiryform@example.com.au';



$headers = 'MIME-Version: 1.0' . '\n.';

$headers .= 'Content-type: text/html; charset=iso-8859-1' . '\n.';

$headers .= 'Content-Transfer-Encoding: 7bit'.'\n.';

$headers .= 'From: $fromaddress' . '\n.' ;

$headers .= 'Reply-To: ' . $fromaddress . '\n.';

$headers .= 'X-Mailer: PHP/' . phpversion();





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

and it still did not send.
my guess, is either something server side or a dot, or comma etc missing.

[edited by: eelixduppy at 11:29 pm (utc) on Mar 30, 2010]
[edit reason] exemplified [/edit]

Readie

10:45 pm on Mar 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$headers .= 'From: $fromaddress' . '\n.' ;

Probably not the problem, but you haven't concatonated ('string' . $variable . 'string') the variable there.

Also, I've always
\r\n
, inside double quotes (as I think they're turned into literals inside single quotes) and never had any problems, so you might try that.

Matthew1980

12:38 pm on Mar 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there MikeSA1965,

Readie is quite right here:-

$headers = 'MIME-Version: 1.0' . '\n\r';
$headers .= 'Content-type: text/html; charset=iso-8859-1\n\r';
$headers .= 'Content-Transfer-Encoding: 7bit\n\r';
$headers .= 'From: '.$fromaddress.'\n\r';
$headers .= 'Reply-To:'.$fromaddress.'\n\r';
$headers .= 'X-Mailer: PHP/'.phpversion();

Also since reading this afresh this morning, this:-

$to = 'tenders@example.com.au';
$subject = 'Enquiry form submitted ' . date("F j, Y, g:i a");
$fromaddress = 'enquiryform@example.com.au';

I think as you can discard the $message var from this chunk of code as you quote it in the mail() anyway, from what I could see there was no need to redeclare it to itself anyway ;-p

So this should just translate to:-

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

already defined here and built further up the script:-

$message = '<html><head><title>Enquirey form</title></head><body>';
$message .= $messagebody;
$message .= '</body></html>';

So in essence, the $messagebody is added to $message there, just echo $message at this point with an exit; directly after it & submit the form to see how the html is looking. And as $message is then placed into the mail(); with $headers, the mail then should go.

See if the suggestion (originally from Readie) helps (as I think it will ;-p)

Cheers,
MRb

MikeSA1965

6:30 am on Apr 6, 2010 (gmt 0)

10+ Year Member



Thanks you Readie and Matthew1980. I have implemented the suggested changes. I still receive no email from posting the form, however, I do get a print out or 'Écho' of the contents of my redirected page. I get the feeling that the problem lies within the php.ini file. I have sent another request to my provider/host to rectify this.
Again thanks for your comments and suggestions. I shall now go back through this page file and rectify all the loose ends as suggested through your comments.

Many Thanks
Mike