How to attach a written file to an email
Posted: Sun Oct 09, 2011 9:04 am
hello sirs,
I have made the following observations:
1) If I have a simple form of about 5 or 10 fields, which a user is supposed to fill - to be sent to an email address: this is a sample code I sourced from the internet.
The above works fine - from my observation with just a couple of fields (inputs, etc).
I have a very very long code with several variables - a table actually, which I want to send by email. I have tested my code using echo statements to display / make sure my outputs are correct and displayed as I want them to be.
So I have them outputted through a single $formcontent - using the above as an example, as in the above with several line breaks in several rows.
My challenge is that if I use the code above, with just a handful of variables, the email goes successfully, but once I paste my code, it doesnt. No errors are displayed anywhere, I can see the Thank you echo - its as if the email went successfully but I dont see the email in my mail box.
So I thought that perhaps because of the size of the file, etc.,
So I set about writing the output into a text file. I have done this and the output is written to a text file in the same DIR as my script is. Now, I want to attach it(written text file) to an email address - hoping that perhaps the above code will work.
Informations gathered on the net include re-reading the text file into a single variable ex: $data and sending the contents to an email address, which is not what I want to do.
What I want to do is the send the text file as an attachment, so that the mail reads something like "please find attached" - then the text file is attached to the email.
questions:
1) is there a limit to the size of content that can be used as a variable, example: $formcontent in code:
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
2) Now that Ive written the output to a text file, how can I send the written file as an attachment to my mail box? not as an inline pasted text information.
regards
Tokunbo
I have made the following observations:
1) If I have a simple form of about 5 or 10 fields, which a user is supposed to fill - to be sent to an email address: this is a sample code I sourced from the internet.
Code: Select all
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
[b]$formcontent[/b]=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "YOUREMAIL@HERE.COM";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
I have a very very long code with several variables - a table actually, which I want to send by email. I have tested my code using echo statements to display / make sure my outputs are correct and displayed as I want them to be.
So I have them outputted through a single $formcontent - using the above as an example, as in the above with several line breaks in several rows.
My challenge is that if I use the code above, with just a handful of variables, the email goes successfully, but once I paste my code, it doesnt. No errors are displayed anywhere, I can see the Thank you echo - its as if the email went successfully but I dont see the email in my mail box.
So I thought that perhaps because of the size of the file, etc.,
So I set about writing the output into a text file. I have done this and the output is written to a text file in the same DIR as my script is. Now, I want to attach it(written text file) to an email address - hoping that perhaps the above code will work.
Informations gathered on the net include re-reading the text file into a single variable ex: $data and sending the contents to an email address, which is not what I want to do.
What I want to do is the send the text file as an attachment, so that the mail reads something like "please find attached" - then the text file is attached to the email.
questions:
1) is there a limit to the size of content that can be used as a variable, example: $formcontent in code:
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
2) Now that Ive written the output to a text file, how can I send the written file as an attachment to my mail box? not as an inline pasted text information.
regards
Tokunbo