-2

I'm fairly new to php and I am trying to use it to collect data from a form I have on my website, then post the content of the forms to my email address, but my send.php script keeps giving me errors.

This is what I have:

$company=$_POST['company'];
$contact=$_POST['contact_person'];
$position=$_POST['position'];
$phone=$_POST['phone'];
$address=$_POST['address'];
$finance=$_POST['finance'];
$items=$_POST['items'];
$kind=$_POST['kind'];
$date=$_POST['date'];

$body="company name:". $company . "<br />Contact person:".$contact."<br />position:"
      .$position."<br />phone:".$phone."<br />address:".$address."<br />finance:".$finance."<br />items:"
      .$items."<br />date:".$date;


$to = "contact@sigmastrat.com"; //your email address
$message = $body ."<br/><hr/><br/>".$content;
$from = $_POST['email'];
$headers = "From:" . $from;
mail($to, $message, $headers);
echo "Mail Sent.";

I keep getting errors on lines 19 and 22:

$message = $body ."<br/><hr/><br/>".$content;  // L19
mail($to, $message, $headers); // L22

What am I doing wrong?

The error msgs are:

Notice: Undefined variable: content in C:\wamp\www\CPIBootstrap\send_d.php on line 19

And:

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\CPIBootstrap\send_d.php on line 22

Esoteric Screen Name
  • 6,082
  • 4
  • 29
  • 38
  • What errors are you getting? – aynber Oct 04 '13 at 18:56
  • Usually, when you get an error, there is a message which tells you what sort of error it is. Knowing what that message says is usually *really* helpful for figuring out what the problem is. – Quentin Oct 04 '13 at 18:57
  • lookup mail on php.net. You mail command misses the subject. `mail($to, $subject, $message, $headers);` – Daniel Oct 04 '13 at 18:58
  • For `one` thing, you're missing a parameter in your `mail()` function, such as the `subject`, being the 2nd parameter. Add `$subject="Form subject";` then do this `mail($to, $subject, $message, $headers);` – Funk Forty Niner Oct 04 '13 at 18:58
  • you are also using an undefined variable `$content` unless you have it created some where else. – Patrick Evans Oct 04 '13 at 18:59
  • also your server isn't running an smtp server. – Doon Oct 04 '13 at 19:03
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – BlitZ Oct 04 '13 at 19:03

2 Answers2

0

Your parameters aren't correct. Check the mail() function.

The correct order is:

mail($to, $subject, $message, $additional_headers)

So, I would try:

mail($to, 'My Subject', $message, $headers);
SeanWM
  • 16,789
  • 7
  • 51
  • 83
0

Your mail() call is incorrect. The syntax is:

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

As well, you're using $content without ever having defined it. So mostlikely that's your two errors - incorrect function call parameters, and undefined variables.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • thanks Marc B... but am left with the last error "Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\CPIBootstrap\send_d.php on line 22" – Kwadwo Asante-Kwabiah Oct 04 '13 at 19:06
  • you need to configure mail server on localhost – Sumit Bijvani Oct 04 '13 at 19:08