Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Sending form data to an email address

Featured Replies

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:

 

$B){ $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?

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?

  • 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?

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.

  • 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 by POWERPLAY27

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 by Wickham

  • 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?

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.

  • 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 by POWERPLAY27

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.

So is it sorted? I'm confused :unsure:

 

If not, what does your code look like now with the changes? Could you show both the HTML & PHP here?

 

Lyndsey.

  • 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 by POWERPLAY27

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 by Lyndsey

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

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.

  • 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

  • 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 by POWERPLAY27

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.