Page 1 of 1

Help! Contact form with attachment..

Posted: Fri May 21, 2010 12:09 pm
by Sassci
I am new to PHP and have been trying for a couple of weeks now to succeed at writing a code for sending an email with an attachment. I am able to load the code in a browser, fill in the necessary info and attach the file yet I am constantly getting error codes once submit is pressed. My latest code is, after being told I needed to install a mail server,
Quote:
Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\xampp\htdocs\email.php on line 46 Failed.
I installed hMailServer onto my pc which is running on Windows Vista HP. I am clueless on how to alter anything dealing with SMTP. I could not find the php.ini file that quite a few people are talking about, all I could locate is a php.ini.h file. Anyway here's the code I am using:

Code: Select all

<?php

if(isset($_POST) && !empty($_POST)) {

if(!empty($_FILES['attachment']['name'])) {

$file_name = $_FILES['attachment']['name'];
$temp_name = $_FILES['attachment']['tmp_name'];
$file_type = $_FILES['attachment']['type'];

$base = basename($file_name);
$extension = substr($base, strlen($base)-4, strlen($base));

$allowed_extensions = array(".doc","docx",".pdf",".png",".jpg");

if(in_array($extension,$allowed_extensions)) {

$from = $_POST['email'];
$to = "myemail@here.com";
$subject = "test with attachment";
$message = "This is a test";

$file = $temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));

$header = "From: ".$from."\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is multi-part message in MIME format. \r\n";

$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message. "\r\n\r\n";

$header .= "--".$uid."\r\n";
$header .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$header .= $content."\r\n\r\n";

if (mail($to, $subject, "", $header)) {
echo "Success";

} else {
echo "Failed";
}

exit();

} else {
echo "File type not allowed";
}
}
}

?>


<html>
<body>
<form method="post" action="email.php" enctype="multipart/form-data">
<input type="text" name="email" value="Enter Email"/>
<br>
<input type="file" name="attachment"/>
<br>
<input type="submit" value="Send Mail"/>

</form>
</body>
</html>
Can anyone offer me some support?

Re: Help!

Posted: Sat May 22, 2010 4:56 am
by social_experiment
Sassci wrote:I could not find the php.ini file that quite a few people are talking about, all I could locate is a php.ini.h file.
php.ini is located in C:\xampp\php\

Re: Help!

Posted: Mon May 24, 2010 12:33 pm
by Sassci
Ummmm... I am not seeing a php.ini file in the Xampp/php area. It doesn't appear to exist in the version I have. Just the php.ini.h file.

Re: Help!

Posted: Tue May 25, 2010 12:42 am
by social_experiment
ok, have you tried re-installing xampp?

Re: Help!

Posted: Tue May 25, 2010 10:13 am
by Jonah Bron
Forum Rules wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
We realize you are frustrated with your problem, but please use relevant subject lines.