pundabuyer
Programmer
Hi Guys,
Im having an issue! I have an html form in a php document that auto submits to itself.
The web form allows a file upload which does upload fine. i use the following code to try and send the form via email to the recipient:
<?
if (isset($_POST['control1'])){
// Load Variables from the form
$'control1'= $_POST['control1'];
// load the other variables here
//Define the email attributes
$filename = $_FILES['file']['tmp_name'];
$fileFinal = $_FILES['file']['name'];
$to = "example@me.co.uk";
$subject = "A new email has arrived";
$random_hash = sha1(date('r', time()));
// Read in our file attachment
$attachment = file_get_contents($filename);
$encoded = base64_encode($attachment);
$attachment = chunk_split($encoded);
$headers = "From: example@me.co.uk\r\nReply-To: example@me.co.uk";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$message = "Hello World!!!";
if ($filename<>null){// ie - a file was uploaded
$message .= "
--PHP-mixed-$random_hash
Content-Type: application/zip; name=$fileFinal
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-mixed-$random_hash";}
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
}
?>
The problem i am having is that this code is very unfamiliar to me. Forget about the actual variables and form data for now, all i need to do is get the Hello world message to send.
if an attachment is selected it does come through but with no hello world message. (it does however come through with an additional ATTxxxx.txt file attached.
If i dont select a file to upload, the code send the email with no file attachment as expected but it does put the hello world message in the email body.
Any help would be MASSIVELY helpful, an explaination of the email code would be beneficial too i am familiar with all of the other PHP code.
Im having an issue! I have an html form in a php document that auto submits to itself.
The web form allows a file upload which does upload fine. i use the following code to try and send the form via email to the recipient:
<?
if (isset($_POST['control1'])){
// Load Variables from the form
$'control1'= $_POST['control1'];
// load the other variables here
//Define the email attributes
$filename = $_FILES['file']['tmp_name'];
$fileFinal = $_FILES['file']['name'];
$to = "example@me.co.uk";
$subject = "A new email has arrived";
$random_hash = sha1(date('r', time()));
// Read in our file attachment
$attachment = file_get_contents($filename);
$encoded = base64_encode($attachment);
$attachment = chunk_split($encoded);
$headers = "From: example@me.co.uk\r\nReply-To: example@me.co.uk";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$message = "Hello World!!!";
if ($filename<>null){// ie - a file was uploaded
$message .= "
--PHP-mixed-$random_hash
Content-Type: application/zip; name=$fileFinal
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-mixed-$random_hash";}
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
}
?>
The problem i am having is that this code is very unfamiliar to me. Forget about the actual variables and form data for now, all i need to do is get the Hello world message to send.
if an attachment is selected it does come through but with no hello world message. (it does however come through with an additional ATTxxxx.txt file attached.
If i dont select a file to upload, the code send the email with no file attachment as expected but it does put the hello world message in the email body.
Any help would be MASSIVELY helpful, an explaination of the email code would be beneficial too i am familiar with all of the other PHP code.