Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. <form action="file-upload.php" method="post" enctype="multipart/form-data">
  2. Файлы:<br />
  3. <input name="photo[]" type="file" /><br />
  4. <input type="submit" value="Отправить" />
  5. </form>
  6.  
  7. <?php
  8. if($_FILES['photo']['name'])
  9. {
  10. //if no errors...
  11. if(!$_FILES['photo']['error'])
  12. {
  13. //now is the time to modify the future file name and validate the file
  14. $mail = new PHPMailer;
  15.  
  16.  
  17. $mail->isSMTP(); // Set mailer to use SMTP
  18. $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
  19. $mail->SMTPAuth = true; // Enable SMTP authentication
  20. $mail->Username = 'user@example.com'; // SMTP username
  21. $mail->Password = 'secret'; // SMTP password
  22. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  23. $mail->Port = 587; // TCP port to connect to
  24.  
  25. $mail->setFrom('from@example.com', 'Mailer');
  26. $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
  27. $mail->addAddress('ellen@example.com'); // Name is optional
  28. $mail->addReplyTo('info@example.com', 'Information');
  29. $mail->addCC('cc@example.com');
  30. $mail->addBCC('bcc@example.com');
  31.  
  32. foreach($_FILES['photo']['tmp_name'] as $key => value) {
  33. $mail->addAttachment($value, "photo-{$key}.jpg"); // Optional name
  34.  
  35. }
  36. $mail->isHTML(true); // Set email format to HTML
  37.  
  38. $mail->Subject = 'Here is the subject';
  39. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  40. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  41.  
  42. if(!$mail->send()) {
  43. echo 'Message could not be sent.';
  44. echo 'Mailer Error: ' . $mail->ErrorInfo;
  45. } else {
  46. echo 'Message has been sent';
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement