Skip to content Skip to sidebar Skip to footer

PHP send email with attachments

Reading Time: < 1 minute

How can you send Email with attachment using php?In this post will describes how to send email with attachments using php.You can download source code and can be view demo.PHPMailer package can be use to this purpose easily.

You can Download PHPMailer from here.
Note: If you run this localhost/wamp/wampp you must check/change the following extensions are enabled or not.

  • php_openssl” Extension
  • upload_max_filesize“, “max_execution_time” and “memory_limit” in the php.ini file.
  • file_uploads” states is “on”
  • smtp_port” is 25.You can change this passing proper value.

This is the form.

Name
Your Email
Message
Attachment

This is the php script to handle the mail process.

'.'Please enter Name'.'';
	}
	// validate email
	if($ToEmail=='') {
		$err .='
  • '.'Please enter Email address'.'
  • '; } // validate attachments if( $attachmentss =='' ) { $err .='
  • '.'Please upload an attachment'.'
  • '; } if($err) { echo '
    '.$err.'
    '; } else { move_uploaded_file($_FILES["attachmentss"]["tmp_name"], "uploads/" . $_FILES["attachmentss"]["name"]); $FromEmail = '[email protected]'; $Subject = 'PHP Send Email with attachments - Example'; $FromName = $name; $mail = new PHPMailer(); $mail->From = $FromEmail; $mail->FromName = $FromName; $mail->Sender = $FromEmail; $mail->ConfirmReadingTo = $FromEmail; $mail->AddReplyTo($FromEmail); $mail->IsHTML(true); $mail->AddAttachment('uploads/'.$attachmentss, $attachmentss); // attachment $mail->Subject = $Subject; $mail->Body = $Message; $mail->AltBody = "ALTERNATIVE MESSAGE FOR TEXT WEB BROWSER LIKE SQUIRRELMAIL"; $mail->AddAddress($ToEmail,$ToEmail); if($mail->Send()){ echo '
    Email has been sent.Check your email account.
    '; } else{ echo '
    Not sent:
    '.print_r(error_get_last(), true).'

    ';
    }
    } // end else
    }
    ?>

    That’s only.
    View Demo

    Download PHP send email with attachments Example (60 KB)