Answer the question
In order to leave comments, you need to log in
How to attach a file from the server to a letter using phpmailer?
Sending an email using phpmailer. I'm trying to attach a file that is on the server. I tried several methods that I found on the Internet:
// $path - абсолютный путь до файла
$path = "https://mysite.ru/files/file.txt": // в таком виде задается
$mail->AddAttachment($path);
$mail->addAttachment(file_get_contents($path));
$mail->addStringAttachment(file_get_contents($path));
$mail->addStringAttachment(file_get_contents($path), "file");
// и всякие другие
Answer the question
In order to leave comments, you need to log in
To properly address this issue, you need to master two important concepts. No, three.
1. Start distinguishing files from virtual addresses . Not that this is necessarily the cause, but specifying a URL instead of a file path is incorrect.
2. Master such a thing as debugging . If something does not work, it most likely writes errors. Mistakes must be read to correct. There is no magic code that always works in general, you just have to "find it on the Internet". Any code may not work for a million reasons beyond its control.
An important takeaway from this is that you don't need to know how to attach files.You already know this. You need to learn to see PHP errors so that you can read them, google them, and eventually fix them.
3. Learn English. And not just randomly copy the code found on the Internet, but also try to figure out what it does. This can be seen even from the names of the functions. And thus discard obviously non-working options like $mail->addAttachment(file_get_contents($path));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question