Sending email with attachment using php’s mail() function
Hello Friends,
All we know how to send email in php. If you are begineer in php than i must say php provides inbuilt mail function named as mail(). Using this function we can implement email functionality very easily just by passing four parameters (to, subject, message and headers). But what if you want to send an attachement with an email ? Today i came across a functionality where i need to send an email with attachment(Sending resume – doc file). Here i am sharing the function using which you can send an email with attachment using php's mail function.
$to = "raxit4u2@gmail.com";
$subject = "Email with attachment";
$random_hash = md5(date('r', time()));
$headers = "From: raxit4u2@gmail.comrnReply-To: raxit4u2@gmail.com";
$headers .= "rnContent-Type: multipart/mixed; boundary="PHP-mixed-".$random_hash.""";
$attachment = chunk_split(base64_encode(file_get_contents("resume.doc")));
$output = "
–PHP-mixed-$random_hash;
Content-Type: multipart/alternative; boundary='PHP-alt-$random_hash'
–PHP-alt-$random_hash
Content-Type: text/plain; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
Hello,
This is testing email with attachment. Please find attachment.
–PHP-alt-$random_hash
Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
Hello,
This is testing email with attachment. Please find attachment.
–PHP-alt-$random_hash–
–PHP-mixed-$random_hash
Content-Type: application/msword; name=resume.doc
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
–PHP-mixed-$random_hash–";
if(mail($to, $subject, $output, $headers))
{
echo 'Mail Sent with an attachment.';
}
Copy the above code for sending attachment emails in php,attachment email using php script,send an email with attachment,php emails with attachment.
Comment below if you have any question.
To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database and Open-source, enter your email address below. We will send you free tutorials.
Related posts:
- POP3/IMAP Email with attachment-Read & Forwarding with PHP
- Implementing Google Maps using API on your website
- Sending email with multiple attachment using php’s mail() function
- How to send email from localhost(XAMPP or WAMP) in PHP in Windows
- Solved – Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent
You can leave a response or trackback from your own site.



I am
Recent Comments