September 24, 201213 yr I have code for sending form data to an email address, which I obtained from PHP5/MYSQL Bible. When I send the form it doesn't seem to be working, this is the output: ${ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.sign-technologies.net/form_sent.htm" );} else {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } } } ?> Is this, because I don't have PHP installed on my computer?
September 24, 201213 yr You will have PHP processing by a browser from an online source but not from a local file unless you install WAMPServer or XAMPP which have Apache server and PHPmyadmin. Even if you have one of those, you can't send an email from a local file unless you edit the PHP.ini file in Wampserver or XAMPP. It't better to upload and test online so that the host server processes the PHP. Have you tried that?
September 24, 201213 yr Author You will have PHP processing by a browser from an online source but not from a local file unless you install WAMPServer or XAMPP which have Apache server and PHPmyadmin. Even if you have one of those, you can't send an email from a local file unless you edit the PHP.ini file in Wampserver or XAMPP. It't better to upload and test online so that the host server processes the PHP. Have you tried that? Nope, how do I go about doing this?
September 24, 201213 yr You upload your html and php files the normal way using an ftp client then fill in the form and submit from the online version. If you set up a database you will also have to set up MySQL database on your host's server (same way you set it up locally but with a different username and password) but I don't think this applies to you although you said PHP5/MYSQL in your first post.
September 24, 201213 yr Author Ok, I've done that..... Here is my php code: <div id="contact"> <form class="contactcontent" name="myForm" enctype="text/plain" "javascript" METHOD="post" ACTION="sent_form.php" onsubmit="return validateForm(myForm)"> <label for="fullname">Full Name:</label> <input type="text" id="fullname" name="fullname" size="40" /><br /><br /> <label for="company">Company:</label> <input type="text" id="company" name="company" size="40" /><br /><br /> <label for="email">Email Address:</label> <input type="text" id="email" name="email" size="40" /><br /><br /> <label for="telno">Contact Tel No:</label> <input type="text" id="telno" name="telno" size="20" /><br /><br /><br /><br /> <label for="enquiry">Please Insert Your Enquiry Here:</label> <br /> <textarea name="enquiry" id="enquiry" rows="10" cols="65" /></textarea><br /><br /> <input type="submit" id="submit" value="Submit" name="submit"/><input type="reset" id="clearFrm" Value="Clear Form" name="Reset"/> </form> </div> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <?php $to = "louis.andre@hotmail.com"; $subject = "Contact_Us"; $email = $_REQUEST['email'] ; $fullname = $_REQUEST['fullname']; $company = $_REQUEST['company']; $telno =$_REQUEST['telno']; $enquiry =$_REQUEST['enquiry'];*/ $headers = "From: $email"; $sent = mail ($to, $subject, $email, $fullname, $company, $telno, $enquiry, $headers); if($sent) {print "Thank you, we have received your enquiry and we will try to respond back to you within 48 hours."; } else{ print "We encountered an error and did not receive your enquiry.";} ?> </body> </html> This coding is not from php/mysql bible, I got it from an internet site I googled a few minutes ago. I've changed what is required to match my form, I looked in my email account, nothing there. I'm getting this error.... Warning: mail() expects at most 5 parameters, 8 given in /homepages/37/d421780152/htdocs/send_form.php on line 21 We encountered an error and did not receive your enquiry. Ok got rid of that error by only using the 5 parameters expected: ($to, $subject, $fullname, $enquiry, $headers); What I don't understand is why only 5 expected? I'm now getting the unsuccessful error alone: "We encountered an error and did not receive your enquiry." On one hand its working as I would like it to, but on the other, the form is not sent to my mail, any ideas why? Edited September 24, 201213 yr by POWERPLAY27
September 24, 201213 yr Try this for your sent_form.php (you don't need the html and body code, just the php): <?php $to = "louis.andre@hotmail.com"; $subject = "Contact_Us"; $email = $_REQUEST['email'] ; $fullname = $_REQUEST['fullname']; $company = $_REQUEST['company']; $telno =$_REQUEST['telno']; $enquiry =$_REQUEST['enquiry'];*/ $admin = "louis.andre@hotmail.com"; $headers = "From: $admin"; $sent = mail ($to, $subject, "$email $fullname $company $telno $enquiry", $headers); if($sent) {print "Thank you, we have received your enquiry and we will try to respond back to you within 48 hours."; } else{ print "We encountered an error and did not receive your enquiry.";} ?> Note that an email can only have four parts, To,Subject, Body and headers(from) so I've put your form names into the third section inside quotes. Note also that I changed $headers = "From: $email"; to $headers = "From: $admin"; and made $admin your email address so you are sending an email to yourself from yourself with the user's email in the body of the email.You don't actually have to do this, but your ISP or host may consider it spam if a lot of emails are apparently being sent from unusual domains through your domain's server (I got my emails blocked when doing that) so it's safer if all emails come from an address at your own domain. EDIT in other words, you should set up an email account on your own domain, not hotmail, so you should edit $admin to something like $admin = "mail@louis.andre.com"; or whatever your domain is. Edited September 24, 201213 yr by Wickham
September 25, 201213 yr Author Thank you for your help, thats sorted it out and I receive an email now when I submit the form, however in the body I only see ", , ," visible (without the quotes) The user input in the form is not sent with the email?
September 25, 201213 yr Author I've changed the method from $_REQUEST to $_POST.....still the same outcome.
September 26, 201213 yr Request or post shouldn't make any differrence, leave it as $_post. Check with just one user input without the quotes just to see if it gets sent $sent = mail ($to, $subject, $email, $headers); If it doesn't, check that there's no difference in lower case/upper case. Otherwise I can't understand it as I use the same method of putting several variables inside quotes for the body section. A variation I use is $sent = mail ($to, $subject, "$email\r\n$fullname\r\n$company\r\n$telno\r\n$enquiry", $headers); which creates a line break between the text in the email.
September 26, 201213 yr Author I tried it, but unfortunately doesn't work. I'm not sending it to my domain email. I'm sending it to my google account, could that in itself be the problem? Edited September 26, 201213 yr by POWERPLAY27
September 26, 201213 yr Try removing enctype="text/plain" from your <form> tag. I think that could be causing it. Extra info here: http://stackoverflow.com/questions/7628249/method-post-enctype-text-plain-are-not-compatible Lyndsey. Edited September 26, 201213 yr by Lyndsey
September 26, 201213 yr Author I thought that might do it, but still same problem. Thanks for response, good guess. Edited September 26, 201213 yr by POWERPLAY27
September 26, 201213 yr Ensure your form tag is correct, like this: <form name="myForm" action="sent_mail.php" method="post" onsubmit="return validateForm(myForm);"> Also, the textarea for enquiry has a stray slash (highlighted below) , remove that: <textarea name="enquiry" id="enquiry" rows="10" cols="65" /></textarea> There's also a CSS comment in your PHP file (highlighted below) which needs to be removed: $enquiry =$_REQUEST['enquiry'];*/ This those issues then try again. Lyndsey.
September 26, 201213 yr Author I realized those mistakes and changed them, the code I posted above I was getting errors, I've sorted those out.
September 26, 201213 yr So is it sorted? I'm confused If not, what does your code look like now with the changes? Could you show both the HTML & PHP here? Lyndsey.
September 26, 201213 yr Author Ok in terms of the actual sending of the email that works, the problem is the user input data is not showing up in the body of the email: New code: <?php $to = "louis.andre@gmail.com"; $subject = "Contact_Us"; $fullname = $_POST['fullname']; $company = $_POST['company']; $email = $_POST['email'] ; $telno =$_POST['telno']; $enquiry =$_POST['enquiry']; $admin= "louis.andre@gmail.com"; $headers = "From: $admin"; $sent = mail ($to, $subject,"$fullname\r\n$company\r\n$email\r\n$telno\r\n$enquiry", $headers); if($sent) {print "Thank you, we have received your enquiry and we will try to respond back to you within 48 hours."; } else{ print "We encountered an error and did not receive your enquiry.";} ?> <div id="contact"> <form class="contactcontent" name="myForm" METHOD="post" ACTION="send_form.php" > <label for="fullname">Full Name:</label> <input type="text" id="fullname" name="fullname" size="40" ><br /><br /> <label for="company">Company:</label> <input type="text" id="company" name="company" size="40" ><br /><br /> <label for="email">Email Address:</label> <input type="text" id="email" name="email" size="40" ><br /><br /> <label for="telno">Contact Tel No:</label> <input type="text" id="telno" name="telno" size="20" ><br /><br /><br /><br /> <label for="enquiry">Please Insert Your Enquiry Here:</label> <br /> <textarea name="enquiry" id="enquiry" rows="10" cols="65"></textarea><br /><br /> <input type="submit" id="submit" value="Submit" name="submit"/><input type="reset" id="clearFrm" Value="Clear Form" name="Reset"/> </form> </div> Edited September 26, 201213 yr by POWERPLAY27
September 26, 201213 yr How about the HTML? Edit: Thanks powerplay. I can't see anything wrong with it. Have you tried echoing the post variables on the php page to see what (if anything) is being passed? Lyndsey. Edited September 26, 201213 yr by Lyndsey
September 26, 201213 yr Author Any ideas, anyone? Why is my user data not appearing in the body of my email? Edited September 26, 201213 yr by POWERPLAY27
September 26, 201213 yr Author I've echo'd $fullname Tried: echo $fullname; output = nothing echo '$fullname'; output = $fullname echo "$fullname"; output nothing. Nothing seems to be passed from the user input for fullname and its the same with the rest.
September 26, 201213 yr Check the basics. Are you seeing Contact Us as the subject of an email that you receive? Are you filling in and submitting the form on your online page from your own website and domain (not submitting from a local file on your computer? Does your host support PHP (if it sends an empty email, it must do). Does your host send emails via php (it seems that it does)? If you edit the mail function to $sent = mail ($to, $subject, "Test Email body", $headers); you should see Test Email body in the email. At least that would check that something is working.
September 26, 201213 yr Author Are you seeing Contact Us as the subject of an email that you receive? YES. Are you filling in and submitting the form on your online page from your own website and domain (not submitting from a local file on your computer? Submitting from own website uploaded FTP. Does your host support PHP (if it sends an empty email, it must do). Believe so, yes it does send the email. Does your host send emails via php (it seems that it does)? Yes
September 26, 201213 yr Author Ok, I absolutely baffled, its now working. I don't know what exactly made it start working, but it has. Thank you all for all your help, you dedicated time to my problem, I appreciate that! Thank you. Edited September 26, 201213 yr by POWERPLAY27
Create an account or sign in to comment