0

I solved problem, changed a bit localisation of files(removed vendor) and it works. Last thing I need to do is adding attachment.

I added line, but still can send only mail without attachment. Aslo created folder upload on catalog with my project.

$file_name = $_POST['file'];
$mail->addAttachment("uploads/".$file_name);

My new working code:

   ```php 
<?php 

    
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
 

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
    
require 'autoload.php';
       
$nameU = $_POST['name'];
$email = $_POST['email'];
$content = $_POST['message'];
$phoneU = $_POST['phone'];
$file_name = $_POST['file'];


$mail = new PHPMailer; //From email address and name 
$mail->From = $email ; 


$mail->FromName = $nameU; //To address and name 
$mail->addAddress("jaroslaw.mor@gmail.com", "Vomo");//Recipient name is optional


$mail->isHTML(true); 
$mail->Subject = "Zapytanie ze strony www"; 
$mail->Body = "Telefon:$phoneU<br>$content";
$mail->AltBody = "Telefon:$phoneU\n$content"; 


$mail->addAttachment("uploads/".$file_name);

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}```
Jaro
  • 35
  • 6
  • So it looks like your current file is `/home/mork/public_html/uploads/vomo/mailer.php`. What is the actual location of the `autoload.php` file? If it's `/home/mork/public_html/uploads/vomo/vendor/autoload.php` then `__DIR__ . '/vendor/autoload.php'` _should work_ – Phil Mar 08 '22 at 00:28
  • You also have to ensure you either run `composer install` on the host or upload all the files in `vendor` if you're using FTP or similar – Phil Mar 08 '22 at 00:32
  • Why would you use `../vendor/autoload.php`? If the `vendor` directory is in the same directory as your `mailer.php` file, then you want `require_once __DIR__ . '/vendor/autoload.php';`. If that can't find other files it needs, it means you haven't uploaded them – Phil Mar 08 '22 at 01:56
  • 1
    Your question is an absolute mess right now. Please just show the current code you're using and any errors it produces. Remove anything else that's not relevant to what you're currently working with. Make sure you format your code so it's readable – Phil Mar 08 '22 at 01:57
  • Does this answer your question? [open\_basedir restriction in effect. File(/) is not within the allowed path(s):](https://stackoverflow.com/questions/1846882/open-basedir-restriction-in-effect-file-is-not-within-the-allowed-paths) – Kristian Mar 08 '22 at 03:32
  • "I solved problem" - so, why not post the solution as an answer? – Nico Haase Mar 08 '22 at 16:01
  • code that I posted, today sends e-mai, it's a solution. In short: removed vendor folder. Last thing that I don't know how to do is add attachment. – Jaro Mar 08 '22 at 16:17
  • Here is your answer https://stackoverflow.com/questions/35997961/file-attachment-with-phpmailer –  Mar 10 '22 at 12:21

0 Answers0