In the PHPMailer class code ( online source on GitHub ) , you can see that in the definition of addAttachment
it says that the attached file must have a path in the file system and that it returns false
if the file can not be opened:
* Add an attachment from a path on the filesystem.
* Returns false if the file could not be found or read.
That's why you do not add the attached file (you pass a URL) and it fails silently. It really is not silent, just do not check if it fails or not, you should add something to check if the result is false or not:
if (!$mail->addAttachment($url,'solicitud.pdf')) {
// código si el archivo no se pudo abrir o leer
}
If the file you want to attach is on a remote server or is a URL, then instead of using addAttachment
you could use addStringAttachment
. In the method definition is specified (my translation):
* Añade una cadena o un binario como adjunto (no en el sistema de archivos)
* Este método puede ser usado para adjuntar ascii o datos binarios
* como por ejemplo un registro BLOB de una base de datos.
One solution to attach the file would be to combine the function file_get_contents
(which read a file as string) with addStringAttachment
(I have not tested the code, it may contain bugs and it would be good if you added some kind of validation for both functions):
$url = 'http://app.pimsaseguros.com/_files/_img/_holidays/040616-160454_img001.pdf';
$fichero = file_get_contents($url);
$mail->addStringAttachment($fichero, 'solicitud.pdf');