How to send Email attachment using core php email function.
1 |
<br /><br /><?php<br />$fileatt = "eporta-consult.png"; // Path to the file<br />$fileatt_type = "image/png"; // File Type<br />$fileatt_name = "eporta-consult.png"; // Filename that will be used for the file as the attachment<br /><br />$email_from = "[email protected]"; // Who the email is from<br />$email_subject = "Your attached file"; // The Subject of the email<br />$email_message = "Thanks for visiting mysite.com! Here is your free file.";<br />$email_message .= "Thanks for visiting.<br />"; // Message that the email has in it<br /><br />$email_to = "[email protected]"; // Who the email is to<br /><br />$headers = "From: ".$email_from;<br /><br />$file = fopen($fileatt,'rb');<br />$data = fread($file,filesize($fileatt));<br />fclose($file);<br /><br />$semi_rand = md5(time());<br /><br />$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";<br /><br />$headers .= "nMIME-Version: 1.0n" . "Content-Type: multipart/mixed;n" . " boundary="{$mime_boundary}"";<br /><br />$email_message .= "This is a multi-part message in MIME format.nn" . "--{$mime_boundary}n" . "Content-Type:text/html; charset="iso-8859-1"n" . "Content-Transfer-Encoding: 7bitnn";<br /><br />$email_message .= "nn";<br /><br />$data = chunk_split(base64_encode($data));<br /><br />$email_message .= "--{$mime_boundary}n" . "Content-Type: {$fileatt_type};n" . " name="{$fileatt_name}"n" . "Content-Transfer-Encoding: base64nn" . $data .= "nn" . "--{$mime_boundary}--n";<br /><br />$ok = @mail($email_to, $email_subject, $email_message, $headers);<br /><br />if($ok) {<br /> echo "<center>You file has been sent<br /> to the email address you specified.<br /> Make sure to check your junk mail!<br /> Click <a href="http://checkconcept.blogspot.com/%5C%22#%5C%22">here</a> to return to mysite.com.</center>";<br />} else {<br /> die("Sorry but the email could not be sent. Please go back and try again!");<br />}<br />?><br /><br /> |
Here we have created a new example where you can able to send email using PHPMailer Class.