Warning: mail() expects at most 5 parameters, 9 given in

I’m working my way through this basic e-mail processing form. I’m very new to PHP so please bear with me. I’m sure this is a very easy problem for you guru’s out there.

I just have a form which is found here: http://www.mcihost.com/naturalchoices/requestinfo.php

If you fill in the blanks and try to process the form you get this message “Warning: mail() expects at most 5 parameters, 9 given in /var/www/html/naturalchoices/email.php on line 185”

I realize what this warning message is saying…here is my code:

<?php
   	  mail("deronsizemore@yahoo.com", "$name", "$email", "$dayphone", "$nightphone", "$regarding", "$othertests", "$healthproducts", "$comments");
  	  echo("Thank you $name for requesting information about Natural Choices");
   	  ?>

I can only have 5 but I have 9 topics if you will, to be submitted through e-mail. Is there a way I can have all 9?

you have mis understood it. the subject content is upto u to put as much data as u wish…

heres sample of ym script

$email=$_POST[‘email’];
$subject=$_POST[‘subject’];
$referer=$_POST[‘referer’];
$message=$_POST[‘message’];

$all=
"email: “.$email.”\r
".
"subject: “.$subject.”\r
".
"referer: “.$referer.”\r
".
"message: “.$message.”\r
";

mail(“mymailaaaa@gmail.com”,$subject,$all,“From: $email”);

what i have done is put all the content of the fields in 1 called $all by joining them togetha.

The format of mail() is:
mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]])
so you put all your variables into $message, in your case an example might be:


$to = 'deronsizemore@yahoo.com';
$subject = 'Some Subject Here';
//build up the message/body part of the email
$message = "$name\
";
$message .= "$email\
";
$message .= "$dayphone\
";
$message .= "$nightphone\
";
$message .= "$othertests\
";
$message .= "$healthproducts\
";
$message .= "$comments\
";
mail($to, $subject, $message);

Edit:

devscripts beat me to it

You’re going to have to cut back :slight_smile:

I use something like this…


mail($toaddress, $subject, $msg, $mailheaders);

So in your case, I’d do something like…


$toaddress = "deronsizemore@yahoo.com";
$subject = "contact form";
$msg = "$name\
";
$msg.= "$email\
";
$msg.= "$dayphone\
";
$msg.= "$nightphone\
";
$msg.= "$regarding\
";
$msg.= "$othertests\
";
$msg.= "$healthproducts\
";
$msg.= "$comments\
";

$mailheaders = "From: $email\
";
$mailheaders .= "To: deronsizemore@yahoo.com\
";
$mailheaders .= "Content-Type: multipart/mixed; \
";

mail($toaddress, $subject, $msg, $mailheaders);

hehe

Thanks for the responses…I don’t fully understand them, but I’ll play around with them and see what I get. This is really the first thing I’ve ever done with PHP.

I must have screwed something up along the way here. I here is my code:

<?php
   	  $toaddress = "deronsizemore@yahoo.com";
	  $subject = "Request Information";
          $msg = "$name\
";
          $msg.= "$email\
";
          $msg.= "$dayphone\
";
          $msg.= "$nightphone\
";
          $msg.= "$regarding\
";
          $msg.= "$othertests\
";
          $msg.= "$healthproducts\
";
          $msg.= "$comments\
";

	  $mailheaders = "From: $email\
";
	  $mailheaders .= "To: deronsizemore@yahoo.com\
";
	  $mailheaders .= "Content-Type: multipart/mixed; \
";
	  mail($toaddress, $subject, $msg, $mailheaders);
  	  echo("Thank you $name for requesting information about Natural Choices!");
   	  ?>

I fill in all of the form fields, click submit, my “Thank you” message appears like it should. I went to test it using my e-mail, I recieved the e-mail with the proper subject, but there was not message…completely blank? Any hints here?

In your email.php script (according to your form source), are you collecting the data okay?

ie. do you have something like this…


$name = $_POST['name'];
$email = $_POST['email'];
...

I am guessing no…

My email.php script is just as shown in my last post…so I have no $name = $_POST [‘name’]; etc… I don’t even know where to put them at?

I see :slight_smile:

You’re going to need some extra bits, something along these lines…


<?php
$name = $_POST['name'];
$email = $_POST['email'];
$dayphone = $_POST['dayphone'];
$nightphone = $_POST['nightphone'];
$regarding = $_POST['regarding'];
$othertests = $_POST['othertests'];
$healthproducts = $_POST['healthproducts'];
$comments = $_POST['comments'];

$toaddress = "deronsizemore@yahoo.com";
$subject = "contact form";
$msg = "$name\
";
$msg.= "$email\
";
$msg.= "$dayphone\
";
$msg.= "$nightphone\
";
$msg.= "$regarding\
";
$msg.= "$othertests\
";
$msg.= "$healthproducts\
";
$msg.= "$comments\
";

$mailheaders = "From: $email\
";
$mailheaders .= "To: deronsizemore@yahoo.com\
";
$mailheaders .= "Content-Type: multipart/mixed; \
";

mail($toaddress, $subject, $msg, $mailheaders);

?>

<!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" lang="en" xml:lang="en">
<head>
<title>Natural Choices, your source for information on Naturopathic Medicine.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META name="description" content="Natural Choices is the internet's source for information on Naturopathic Medicine in Central Kentucky.">
<META name="keywords" content="cancer, heart disease, homeopathy, natural healing, natural medicine, dietary supplement, holistic health, environmenal health, optimum health, kentucky naturopathic physician, blood analysis, optimize your health, allery testing">
<META name="robots" content="index,follow">
<body>

Thank you <?=$name?> for requesting information about Natural Choices!");

</body>
</html>

I appreciate all of your help and patience…I’ll try that and see what happens.

Is there anyway you could give me a brief overview of everything in this script?? Like each part or why its there? Its great to have it and be able to use it, but by just copying the code I’m not really learning how it works or what’s going on with it? Yah know. I understand if you don’t want to explain everything to me…if you have a website that gives some details that’d be cool too.

thanks
Deron

Well briefly, the $_POST bit is an array of information posted from your form, while $_POST[‘name’] specifically holds the information enter in the form field labeled name.

The variable $name is given the value of whatever is in $_POST[‘name’] for later use.

The $msg.= builds up the $msg variable a line at a time by adding all the collected information.

The mail headers part is all smoke and mirrors that is beyond my pay scale :slight_smile:

A good place to get all the information is www.php.net.

I appreciate it. I’ll check that site out. I’ll try that example of yours too and see what I can come up with.

Lats,

Alright, I don’t know if I’m making this way to hard or what, but I cannot get this to work… Even after your fix it does the same exact thing. It will post a message saying “thanks for requesting info…” I will recieve an email with the subject “request info” and the message is blank! What gives?? I’m going to post what I have done completely, so maybe we can pinpoint this.

Here is my form URL: www.mcihost.com/naturalchoices/requestinfo.php

Here is my code from email.php which includes the php processor script:

<!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" lang="en" xml:lang="en">
<head>
<title>Natural Choices, your source for information on Naturopathic Medicine.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META name="description" content="Natural Choices is the internet's source for information on Naturopathic Medicine in Central Kentucky.">
<META name="keywords" content="cancer, heart disease, homeopathy, natural healing, natural medicine, dietary supplement, holistic health, environmenal health, optimum health, kentucky naturopathic physician, blood analysis, optimize your health, allery testing">
<META name="robots" content="index,follow">
<style type="text/css">
body, html {
height: 100%;
}
body {
margin: 0;
background: #ffffff;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 12px;
text-align: center;
}
#container {
_height: 100%;
min-height: 100%;
margin: auto;
width: 750px;
border-left: 1px solid #000000;
border-right: 1px solid #000000;
background:   url(images/containerbg.jpg) repeat-y left top;
text-align: left;
position: relative;
}
#navbar {
border-top: 1px solid #cccccc;
border-bottom: 1px solid #cccccc;
background: #ffffff;
height: 16px;
padding-left: 25px;
}
ul#nav li {
text-align: center;
}
ul#nav li ul li {
text-align: left;
}
ul { /* all lists */
padding: 0;
margin: 0;
list-style: none;
position: relative; /*for ie to show borders */
}
li { /* all list items */
float: left;
position: relative;
width: 11em;
background: #ffffff;
height: 16px;
}
li ul { /* second-level lists */
display: none;
position: absolute;
left: -5px;
top: 100%;
background: #ffffcc;
padding-left: 0px;
}
li ul a {
background-color: #99cc99;
color: #000000;
text-decoration: none;
float: left;
margin: 0;
width: 140px;
padding-left: 0px;
border-top: 1px solid #cccccc;
}
li ul a:hover {
background-color: #99cc99;
color: #ffffff;
}
li>ul { /* to override top and left in browsers other than IE, which will position to the top right of the containing li, rather than bottom left */
top: auto;
left: auto;
margin-left: -1px;
}
li:hover ul, li.over ul { /* lists nested under hovered list items */
display: block;
}
li a {
text-decoration: none;
display: block;
color: #666666;
height: 16px;
}
li a:hover {
color: #3333ff;
height: 16px;
}
#content {
margin-left: 100px;
padding-top: 10px;
padding-right: 5px;
padding-bottom: 5px;
clear: left;
}
#welcome {
margin-bottom: 3px;
}
#firstp {
margin-bottom: 5px;
}
#firstp img{
float: left;
margin-right: 5px;
border: 1px solid #000000;
}
#secondp {
margin-bottom: 5px;
}
#thirdp {
margin-bottom: 5px;
}
#forthp {
margin-bottom: 5px;
}
#fifthp {
margin-bottom: 10px;
}
#fifthp a {
text-decoration: none;
color: #3333ff;
}
#fifthp a:hover {
text-decoration: underline;
}
</style>

<script type="text/javascript"><!--//--><![CDATA[//><!--
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
window.onload=startList;

//--><!]]></script>
</head>

<body>
<div id="container">
  <div id="header"> <img src="images/naturalchoicesheader.jpg" /> </div>
  <div id="navbar">
    <ul id="nav">
      <li><a href="index.php"><strong>Home</strong></a></li>
      <li><a href=""><strong>Health Products</strong></a>
        <ul>
          <li><a href="cleansingp.php">&nbsp;Cleaning Products</a></li>
          <li><a href="personalhc.php">&nbsp;Personal Health Care</a></li>
          <li><a href="skincare.php">&nbsp;Skin Care</a></li>
          <li><a href="cosmetics.php">&nbsp;Cosmetics</a></li>
        </ul>
      </li>
      <li><a href=""><strong>Health Testing</strong></a>
        <ul>
          <li><a href="bloodanalysis.php">&nbsp;Blood Analysis</a></li>
          <li><a href="othertests.php">&nbsp;Other Tests</a></li>
        </ul>
      </li>
      <li><a href="eegneuro.php"><strong>EEG Neurofeedback</strong></a></li>
      <li><a href="requestinfo.php"><strong>Request Info</strong></a></li>
    </ul>
  </div>
  <div id="content">
    	
```php
&lt;?php
		$name = $_POST['name'];
		$email = $_POST['email'];
		$dayphone = $_POST['dayphone'];
		$nightphone = $_POST['nightphone'];
		$regarding = $_POST['regarding'];
		$othertests = $_POST['othertests'];
		$healthproducts = $_POST['healthproducts'];
		$comments = $_POST['comments'];
   	    $toaddress = "deronsizemore@yahoo.com";
	    $subject = "Request Information";
        $msg = "$name\
";
        $msg.= "$email\
";
        $msg.= "$dayphone\
";
        $msg.= "$nightphone\
";
        $msg.= "$regarding\
";
        $msg.= "$othertests\
";
        $msg.= "$healthproducts\
";
        $msg.= "$comments\
";

	    $mailheaders = "From: $email\
";
	    $mailheaders .= "To: deronsizemore@yahoo.com\
";
	    $mailheaders .= "Content-Type: multipart/mixed; \
";
	    mail($toaddress, $subject, $msg, $mailheaders);
  	    echo("Thank you $name for requesting information about Natural Choices!");
   	    ?&gt;
```

I don’t know…sorry to be a hassle, but I’m not understanding even more now what’s happening. lol. If it works for you then should work for me I’d think?

We’ll get there :slight_smile:

I copied the source from your link and copied it to my local system, and used just the code from post# 11 above as email.php.

I can’t test the live email part right now as I’m at work, so I added echo $msg right after the mail command.

After entering some data from the form, it got echoed back.

Try that, and see if you get anything echoed back to the screen.

Use \r
to separate mail headers rather than just \


$mailheaders = "From: $email\\r\
";
$mailheaders .= "To: deronsizemore@yahoo.com\\r\
";
$mailheaders .= "Content-Type: multipart/mixed\\r\
";

Maybe I misunderstood…or you misunderstood me…either way it doesn’t matter but just to be sure. I get the effect I’m looking for as far as echoed back to me on the screen after I click submit. I even recieve the e-mail saying who the message is from, and the subject. Only when I open the e-mail it is blank…so it seems everything is working right except for displaying the message part of the e-mail? Is this what you were telling me to do? I was under the impression that using echo was only to display something in the web browser?? Right, not right?

Mark,

I tried what you posted as well and got this back…"
Parse error: parse error in /var/www/html/naturalchoices/email.php on line 207"??

That right, it’s one of the ways to debug a script.

Parse error: parse error in /var/www/html/naturalchoices/email.php on line 207"??

There aren’t 207 lines in post #11.

If you could use the example (#11), you can easily add any extra bits later, once the basics are running well.

Yeah, but there are 207 + lines of code in the website as a whole. This is what its talking about I believe. With the CSS and html.

Let me to back and just start from the begining. I’m just going to use what was wrote in post 11 like you said and then add more stuff later if it works. I mean if you used this before it should work for me…there’s just something I’m not doing.

As far as adding echo$msg after the mail command…I’m not sure what the mail command is. ( you can bet after I get this figured out I’m going to read up on PHP a lot) Sorry, I’m sure you getting aggrivated because I’m trying to jump in and do something I’m not really ready for yet.