Page 1 of 1

Php Mail form

Posted: Tue Jun 09, 2009 12:16 pm
by moe180
hi, I have to tell you straight off that I am very new to php and really am stuck, I do not know what I have done wrong please help...

This is the php code I have used-

Code: Select all

 
<?php
$to = "myemailaddress@hotmail.co.uk";
 
$phone      = $_POST['phone'];
$name    = $_POST['name'];
$subject = $_POST['subject'];
$address = $_POST['address'];
$message = $_POST['message'];
 
 
$fileatt      = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
 
$headers = "From: $from";
 
if (is_uploaded_file($fileatt,'rb'); 
  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);
 
  
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  
  
  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: multipart/mixed;\n" .
              " boundary=\"{$mime_boundary}\"";
 
  
  $message = "This is a multi-part message in MIME format.\n\n" .
             "--{$mime_boundary}\n" .
             "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
             "Content-Transfer-Encoding: 7bit\n\n" .
             $message . "\n\n";
 
  
  $data = chunk_split(base64_encode($data));
 
  // Add file attachment to the message
  $message .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              //"Content-Disposition: attachment;\n" .
              //" filename=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
              $data . "\n\n" .
              "--{$mime_boundary}--\n";
}
 
 
$ok = ($phone, $subject, $message, $name, $address, $headers);
if ($ok) {
  echo "<p>Thankyou your mail has been sent</p>";
 else {
  echo "<p>Mail could not be sent. Sorry!</p>";
}
?>
 
my html code is-
 
<html>
<head>
<title>Contact</title>
</head>
<body>
<h1>contact</h1>
<form action="mail.php" method="POST" enctype="multipart/form-data">
<p>Name: <input type="text" name="Name" value="" /><br />
Telephone: <input type="text" name="telephone" value="" /><br />
Subject: <input type="text" name="subject" value="" /><br/>
Address: <input type="text" name="address" value="" /></p>
<p>Message:<br />
<textarea cols="20" rows="10" name="message"></textarea></p>
<p>File Attachment: <input type="file" name="fileatt" /></p>
<p><input type="submit" value="Send" /></p>
</form>
</body>
</html>
 
and whenever I fill the form and press send I get-

Parse error: syntax error, unexpected ',' in E:\domains\m\my website address\user\htdocs\mail.php on line 60

I cannot figure out my mistake, so any help and ideas would be much appreciated.

Thankyou in advance for all your help.
Moe.

Re: Php Mail form

Posted: Tue Jun 09, 2009 12:20 pm
by jayshields
This line is the culprit:

Code: Select all

$ok = ($phone, $subject, $message, $name, $address, $headers);
It should be a call to mail(), but you're specifying incorrect parameters for that function anyway.

Re: Php Mail form

Posted: Tue Jun 09, 2009 12:36 pm
by moe180
thankyou jay,
what do you mean incorrect parameters, i am sorry if this is a stupid question but it took me 3 days and a book to get this far and almost losing my mind with it. lol

how do I correct it so it works?

Re: Php Mail form

Posted: Wed Jun 10, 2009 5:55 am
by moe180
Ok so I have tried to change the perameters and and replace the mail request but I cannot get it to work, I have no idea what I am doing wrong I have been through the books I have and cannot find the solution. I can only assume I have tried to run before I can walk..lol
If someone has the solution to my code please tell me, I am getting desperate!!!!!!

Re: Php Mail form

Posted: Wed Jun 10, 2009 7:48 am
by mikemike

Code: Select all

$ok = ($phone, $subject, $message, $name, $address, $headers)
For started you're not calling any function as you've missed out the word 'mail' from before the parenthesis. Secondly, mail() takes a maximum of 5 arguements (the variables in the parenthesis), although you'd only really use 4 - but you're trying to give it 6.

I'm not sure why you're trying to give it a phone number and a name. The attributes should be in this order:
Email recipient - Email address of who should receive the email
Subject - Subject of the email
Message - The message text
-----------------------------
Headers - Things that tell the email client how the email is to be hehave, is it a HTML email? Does it have an attachment? What is the 'reply-to' address, etc. This is optional.

So an example of mail() may be:

Code: Select all

$msg = "Hey Mike,
 
How are things?  Just dropping you and email to see how everything is going.  See you on the weekend.
 
Joe";
 
mail('me@example.com', 'Mikes email subject', $msg, "From: Joe Bloggs <joe@example.com>");
If you need any further help then post back.